on 06-04-2012 9:56 AM
Hello Experts,
I need to search a particular type nodes( for example: workspace ) from the following XML.
<app:service xml:base="http://XXX/XXXX/IWFND/RMTSAMPLEFLIGHT/">
<app:workspace>
<atom:title type="text">Data</atom:title>
<app:collection sap:pageable="false" sap:content-version="1" href="BookingCollection"></app:collection>
<app:collection sap:creatable="false" sap:deletable="false" sap:content-version="1" href="CarrierCollection"></app:collection>
<app:collection sap:label="Travel Agencies" sap:searchable="true" sap:content-version="1" href="TravelagencyCollection"></app:collection>
<app:collection sap:searchable="true" sap:content-version="1" href="TravelAgencies"></app:collection>
<app:collection sap:content-version="1" href="SubscriptionCollection"></app:collection>
<app:collection sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:addressable="false" sap:content-version="1" href="NotificationCollection"></app:collection>
<app:collection sap:content-version="1" href="FlightCollection"></app:collection>
</app:workspace>
<atom:link rel="self" href="http://XXX/XXX/RMTSAMPLEFLIGHT/"/><atom:link rel="latest-version" href="http://XXXX/XXXX/RMTSAMPLEFLIGHT/"/>
</app:service>
To get reference of the node I am using following code snippet.
lcl_xml_doc TYPE REF TO cl_xml_document,
CREATE OBJECT lcl_xml_doc .
CALL METHOD lcl_xml_doc->parse_string
EXPORTING
stream = rv_result (rv_result is of type STRING and it holds the above XML)
RECEIVING
retcode = v_subrc.
data: node_one type ref to if_ixml_node.
node_one = lcl_xml_doc->m_document->find_from_name( name = 'workspace' ).
However the the above method always returns null and the node_one is always empty ..
Can you tell me where I am wrong ?
Thanks in Advance
Hi Atanu,
I'd rather the Greg option because it is a more direct way to acces the value. I think that your problem could be because you are not using the import parameter namespace, and this can generate problems in order to do the search.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Inaki and Grzegorz ,
Thanks for your valuable inputs.
I am now able to get the node after passing the NAMESPACE parameter. So now the code looks like,
data: node_one type ref to if_ixml_node.
node_one = lcl_xml_doc->m_document->find_from_name( name = 'workspace' NAMESPACE = 'app' ).
However I also tried to follow Grzegorz's suggestion and I have used method FIND_NODE. But this time it did not return any node.
Data: lcl_xml_doc TYPE REF TO cl_xml_document,
v_node = lcl_xml_doc->find_node( NAME = 'workspace' ) .
The rest of the code remains as it is.
Could you please help me on this.
Best Regards.
Thanks Inaki for your reply.
As per the scenarios faced here, I find the methods, which does not take NAMESPACE as parameter always fail for my XML. The methods which take the NAMESPACE seem to have fetch the correct node.
For this reason lcl_xml_doc->m_document->find_from_name fetches the node whereas method lcl_xml_doc->find_node fails as it does not take any NAMESPACE as parameter.
I am facing similar problem while trying to fetch the attributes for the node, where I have to send the NAMESPACE along with the ATTRIBUTE name.
For the same reason the filters were also failing .
Is this a correct behavior or something is incorrect in my XML?
Best Regards,
Atanu
Hi Atanu,
At first your XML is totally correct, it's neccesary to find the correct method which works properly with namespaces. You should quit the "Correct Answer" in my answer because you have the problem yet and more people can help you in this thread.
For the atributte you could use the method GET_ATTRIBUTE_NODE_NS in the IF_IXML_ELEMENT interface. In the URI parameter you put the namespace like this case:
l_attr = l_root->get_Attribute_Node_NS(
uri = 'http://schemas.xmlsoap.org/soap/envelope'
name = 'mustUnderstand' ).
Regards,
Hi Iñaki ,
Thanks for response.
Here my requirement is , I have the reference to a NODE, and I would like to read the value of a particular attribute of that node. My code looks like
********************************
data: lr_child TYPE REF TO if_ixml_node ,
lr_child = lr_iterator_child->get_next( ).
while not lr_child is INITIAL .
" here I need the code to fetch the attribute value for a particular attribute for this node
lr_child = lr_iterator_child->get_next( ).
endwhile.
************************************
Here I do not have any reference to the 'ELEMENT', I only have the reference to the node.NODE offers only GET_ATTRIBUTES method which does not take any parameter.
However after using GET_ATTRIBUTES and applying an filtered iterator can be used, but it bocomes a little overburden for this scenario.
Any other approach possible ?
Best Regards,
Atanu
Hi,
First of all, check if this m_document attribute of your object contains the document. You might also try with different methods of the cl_xml_document class, like FIND_NODE (to get the whole node) or FIND_SIMPLE_ELEMENT (to get the value of the 'workspace' node).
Regards,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.