以下问题:我有一个XML文档,我将使用SAP ABAP阅读。看起来这样:
<n0: someName >
<n0: someOtherName >
<n1: underName />
<n16: underUnderStuff />
</n0: someName>
</n0: someOtherName>
因此,问题似乎是N0,N1等。我已将其删除以进行测试并起作用。在ABAP中使用Find_note时,程序只能读取第一行。搜索例如第二个是行不通的。有人知道如何忽略N0等吗?片段请。
您可以使用cl_xslt_processor在ABAP中使用XPATH功能来查找元素。
REPORT zmky_xml_localname.
DATA: lv_string TYPE string,
lv_xstring TYPE xstring,
lv_document TYPE REF TO if_ixml_document,
lo_processor TYPE REF TO cl_xslt_processor,
lo_nodes TYPE REF TO if_ixml_node_collection,
lo_node TYPE REF TO if_ixml_node,
lv_i TYPE i.
CONCATENATE
'<n0:someName xmlns:ns0="http://ns0">'
'<n0:someOtherName>'
'<n1:underName xmlns:ns0="http://ns1"/>'
'<n16:underUnderStuff xmlns:ns0="http://ns16">underUnderStuffValue</n16:underUnderStuff>'
'</n0:someName>'
'</n0:someOtherName>'
INTO lv_string.
lv_xstring = cl_proxy_service=>cstring2xstring( lv_string ).
CALL FUNCTION 'SDIXML_XML_TO_DOM'
EXPORTING
xml = lv_xstring
IMPORTING
document = lv_document
EXCEPTIONS
invalid_input = 1
OTHERS = 2.
CREATE OBJECT lo_processor.
lo_processor->set_source_node( node = lv_document ).
lo_processor->set_expression( expression = '//*[local-name()="underUnderStuff"]' ).
lo_processor->run( progname = space ).
lo_nodes = lo_processor->get_nodes( ).
CHECK lo_nodes IS NOT INITIAL.
lv_i = lo_nodes->get_length( ).
WRITE: 'Item count: ', lv_i.
CHECK lv_i IS NOT INITIAL.
lo_node = lo_nodes->get_item( index = 0 ).
CHECK lo_node IS NOT INITIAL.
lv_string = lo_node->get_value( ).
WRITE /: lv_string.