Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

how to use xpath function to select some particular nodes

Former Member
0 Likes
2,266

Dear experts:

does abap supports xpath to sellect particular nodes according some node value or condition, i know other programe language supports the function selectNode(xpath expression) , does abap or have the api to support it?

and i know there is a class support the xpath but it's not work., the class this:cl_xslt_processor

to clarify my point. i take a ex.

the xml doc is follow:

<?xml version="1.0" encoding="utf-8" ?>

- <n0:MT_CRM_Req xmlns:n0="http://gome.com/CRM/CRM/Outbound" xmlns:prx="urn:sap.com:proxy:DC0:/1SAI/TAS05C79364B9D0DC5F6738:701:2010/02/19">

<company name="hp">

<dep name="gds">

<empolyeeid>123</empolyeeid>

</dep>

<dep name="its">

<empolyeeid>148</empolyeeid>

</dep>

</company>

<company name="foxconn">

<dep name="fih">

<empolyeeid>569</empolyeeid>

</dep>

</company>

</n0:MT_CRM_Req>

i want to select the employee 's company name who empolyee id is 123

i use the method ,and the code is :

l_xslt->set_expression(

expression = '/n0:MT_CRM_Req/n0:company[n0:dep/n0:empolyeeid=123]'

nsdeclarations = 'n0 http://gome.com/CRM/CRM/Outbound'

).

l_xslt->run('').

nodes = l_xslt->get_nodes( ).

LEN = nodes->GET_LENGTH( ) .

WRITE LEN.

but no nodes return.

is anybody knows what's wrong with it? or there is some other api to manipulate the xml dom.

best regrds!

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
959

Hi Kevin liang,

Yes XSLT is supported by ABAP (most part of XSLT standard (so XPath too), SAP library describes a few limitations -> http://help.sap.com/saphelp_nw70/helpdata/en/92/af463c36a30319e10000000a114084/frameset.htm).

About the use of CL_XSLT_PROCESSOR->SET_EXPRESSION, I think your code is mostly correct except I don't see when you load your XML source? If you did, maybe the namespaces could be the cause of the issue, did you try to simplify by removing them?

BR

Sandra

Dear experts:

does abap supports xpath to sellect particular nodes according some node value or condition, i know other programe language supports the function selectNode(xpath expression) , does abap or have the api to support it?

and i know there is a class support the xpath but it's not work., the class this:cl_xslt_processor

to clarify my point. i take a ex.

the xml doc is follow:

<?xml version="1.0" encoding="utf-8" ?>

- <n0:MT_CRM_Req xmlns:n0="http://gome.com/CRM/CRM/Outbound" xmlns:prx="urn:sap.com:proxy:DC0:/1SAI/TAS05C79364B9D0DC5F6738:701:2010/02/19">

<company name="hp">

<dep name="gds">

<empolyeeid>123</empolyeeid>

</dep>

<dep name="its">

<empolyeeid>148</empolyeeid>

</dep>

</company>

<company name="foxconn">

<dep name="fih">

<empolyeeid>569</empolyeeid>

</dep>

</company>

</n0:MT_CRM_Req>

i want to select the employee 's company name who empolyee id is 123

i use the method ,and the code is :

l_xslt->set_expression(

expression = '/n0:MT_CRM_Req/n0:company[n0:dep/n0:empolyeeid=123]'

nsdeclarations = 'n0 http://gome.com/CRM/CRM/Outbound'

).

l_xslt->run('').

nodes = l_xslt->get_nodes( ).

LEN = nodes->GET_LENGTH( ) .

WRITE LEN.

but no nodes return.

is anybody knows what's wrong with it? or there is some other api to manipulate the xml dom.

best regrds!

3 REPLIES 3
Read only

Former Member
0 Likes
959

Hello Kevin ,

i think you can get those details , have a look at program BCCIIXMLT1, i think this program will give you some idea to handle * manage xml docs.

along with that program ...you need to put filter

*---creating filers.

filter = document->create_filter_name( name = 'Company' ).

iterator = document->create_iterator_filtered( filter ).

main_node = document.

*---processing document.

perform print_node using main_node p_flag.

let me know if you need anymore help.

regards

Prabhu

Read only

Sandra_Rossi
Active Contributor
0 Likes
960

Hi Kevin liang,

Yes XSLT is supported by ABAP (most part of XSLT standard (so XPath too), SAP library describes a few limitations -> http://help.sap.com/saphelp_nw70/helpdata/en/92/af463c36a30319e10000000a114084/frameset.htm).

About the use of CL_XSLT_PROCESSOR->SET_EXPRESSION, I think your code is mostly correct except I don't see when you load your XML source? If you did, maybe the namespaces could be the cause of the issue, did you try to simplify by removing them?

BR

Sandra

Read only

Sandra_Rossi
Active Contributor
0 Likes
959

Hi,

kevin liang wrote

l_xslt->set_expression(
   expression = '/n0:MT_CRM_Req/n0:company[n0:dep/n0:empolyeeid=123]'
   nsdeclarations = 'n0 http://gome.com/CRM/CRM/Outbound'
   ).

The error was just the n0 to remove at company, dep and empolyeeid:


l_xslt->set_expression(
  expression = '/n0:MT_CRM_Req/company[dep/empolyeeid=123]'
  nsdeclarations = 'n0 http://gome.com/CRM/CRM/Outbound'
  ).

BR

Sandra