Code: Alles auswählen.
data:
lr_processor type ref to cl_xslt_processor,
lr_document type ref to if_ixml_document,
lr_collection TYPE REF TO if_ixml_node_collection,
ld_xpath type STRING.
CREATE OBJECT lr_processor.
lr_processor->set_source_node( node = lr_document ). "Den Prozessor mit dem Dokument verknüpfen
lr_processor->set_expression( expression = ld_xpath ). "Die XPATH Query übergeben
lr_processor->run( progname = space ). "Die Query verarbeiten
lr_collection = lr_processor->get_nodes( ). "Das Ergebnis
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag (Insgesamt 3):
ewx • bancbanus • fr-g
Code: Alles auswählen.
data(xpp) = new cl_proxy_xpath( ).
xpp->set_source_string( smis-request_payload ). "Dein XML Dokument als STRING
xpp->run( expression = '//element1/subelement2' ).
data(nodes) = xpp->get_nodes( ).
"Die Werte von alle zurückgegebene Knoten ermitteln:
data(node) = nodes->get_next( ).
while node is bound.
write: / node->get_value( ).
node = nodes->get_next( ).
endwhile.
Code: Alles auswählen.
* LCL_XPATH_UTIL is just a simple wrapper for CL_XSLT_PROCESSOR
* to facilitate one-shot XPath queries on XML strings
class lcl_xpath_util definition.
public section.
data: xp type ref to cl_xslt_processor.
methods: constructor,
query importing xml type clike
query type clike
returning value(nodes) type ref to if_ixml_node_iterator.
endclass.
class lcl_xpath_util implementation.
method constructor.
create object xp.
endmethod.
method query.
try.
xp->set_source_string( xml ).
xp->set_expression( query ).
xp->run( ' ' ).
data(node_list) = xp->get_nodes( ).
if node_list is bound and node_list->get_length( ) > 0.
nodes = node_list->create_iterator( ).
endif.
catch cx_xslt_runtime_error.
endtry.
endmethod.
endclass.
...
data(lr_xu) = new lcl_xpath_util( ).
data(nodes) = lr_xu->query( query = '//Log/Item' xml = ls_smis-response_payload ).
Code: Alles auswählen.
data:
lr_processor type ref to cl_xslt_processor,
lr_document type ref to if_ixml_document,
lr_collection TYPE REF TO if_ixml_node_collection,
ld_namespace TYPE string
ld_xpath TYPE string.
* z.B. für den Namespace 'xmlns="urn:hl7-org:v3"' im Quelldokument
ld_namespace = 'hl7 urn:hl7-org:v3'.
ld_xpath = 'hl7:ClinicalDocument/hl7:documentationOf/hl7:serviceEvent/hl7:code'.
lr_processor = new #( ).
lr_processor->set_source_node( node = lr_document ). "Den Prozessor mit dem Dokument verknüpfen
lr_processor->set_expression( expression = ld_xpath "Die XPATH Query übergeben
nsdeclarations = ld_namespace ). "Das Namespace-Mapping übergeben
lr_processor->run( progname = space ). "Die Query verarbeiten
lr_collection = lr_processor->get_nodes( ). "Das Ergebnis