01-28-2011 9:19 AM
Hi all,
I have a problem by using the method cl_xslt_processor->set_expression( expression = ... nsdeclarations = ... ). I want to use this method to get some nodes by using Xpath.
My problem is the parameter 'nsdeclarations' which should be filled like 'prefix1 URI1 prefix2 URI2 ...'. But my xml document has no prefix. It looks like
<ROOT xmlns="http://uri">....</ROOT>
After getting a node collection I create a iterator und try to get the first element ( lr_element ?= lr_iterator->get_next( ). )
But lr_element is always initial. I tried to call the method without the parameter 'nsdeclarations' (is optional) but it didn't work, as well as passing only the uri.
If I put a prefix into my xml and my namespace parameter it works.
Does anybody have an idea what has to be passed in my case (no namespace prefix)?
Thanks in advance.
Best regards
Guenter
01-28-2011 10:12 AM
Hi,
You have to map default namespance to your own prefix and the use it in the XPath.
See example where I declare 'my' prefix
DATA l_xslt TYPE REF TO cl_xslt_processor.
DATA: nodes TYPE REF TO if_ixml_node_collection.
CREATE OBJECT l_xslt TYPE cl_xslt_processor.
l_xslt->set_source_string(
'<?xml version="1.0" encoding="ISO-8859-1"?>' &
'<a xmlns="http://uri.com">' &
'<foo>bar</foo>' &
'</a>' ).
l_xslt->set_expression(
expression = 'my:a/my:foo'
nsdeclarations = 'my http://uri.com'
).
l_xslt->run( '' ).
nodes = l_xslt->get_nodes( ).
01-28-2011 10:12 AM
Hi,
You have to map default namespance to your own prefix and the use it in the XPath.
See example where I declare 'my' prefix
DATA l_xslt TYPE REF TO cl_xslt_processor.
DATA: nodes TYPE REF TO if_ixml_node_collection.
CREATE OBJECT l_xslt TYPE cl_xslt_processor.
l_xslt->set_source_string(
'<?xml version="1.0" encoding="ISO-8859-1"?>' &
'<a xmlns="http://uri.com">' &
'<foo>bar</foo>' &
'</a>' ).
l_xslt->set_expression(
expression = 'my:a/my:foo'
nsdeclarations = 'my http://uri.com'
).
l_xslt->run( '' ).
nodes = l_xslt->get_nodes( ).