07-14-2015 9:32 PM
Hi there,
I'm facing a problem while I try to parse a XML file.
This is my code:
DATA: o_xml_document TYPE REF TO cl_xml_document.
DATA: v_tag_value TYPE string.
CREATE OBJECT o_xml_document TYPE cl_xml_document.
o_xml_document->parse_xstring( v_xml_xstring ). " <<<<--- it's ok, I already have this
v_tag_value = o_xml_document->find_simple_element( name = 'infCarga'). <<--- this is the tag name that I need
WRITE: / v_tag_value. "
Result:
33398.98FRASCO VIDROPALLET03VOLUMES7819.936003VOLUMES16.0000
I would like to get tag names and values... (vCarga = 333398.98, proPred=......)
Does anyone could suggest me something?
07-14-2015 10:43 PM
You can either create the simple transformation to convert the XML into your data structure. Or else, you would need to loop through the kids of the specific node.
DATA: o_xml_document TYPE REF TO cl_xml_document. DATA: v_tag_value TYPE string. DATA: lo_kid_1 TYPE REF TO if_ixml_node. DATA: lv_name TYPE string, ENDWHILE. |
This sample XML
<?xml version="1.0" encoding="utf-8"?>
<infCarga>
<vCarga>10000.00</vCarga>
<proPred>PNEU</proPred>
<xOutCat>GRANEL</xOutCat>
<infQ>
<cUnid>01</cUnid>
<tpMed>PESO BRUTO</tpMed>
<qCarga>13.0000</qCarga>
</infQ>
<infQ>
<cUnid>03</cUnid>
<tpMed>UNIDADE</tpMed>
<qCarga>500.0000</qCarga>
</infQ>
</infCarga>
Would generate this output
vCarga 10000.00
proPred PNEU
xOutCat GRANEL
cUnid 01
tpMed PESO BRUTO
qCarga 13.0000
cUnid 03
tpMed UNIDADE
qCarga 500.0000
Regards,
Naimesh Patel
07-14-2015 10:11 PM
Hi Thiago,
I think you will have to get the children of that node (infCarga), loop through that and get the individual values .
Thanks,
Juwin
07-14-2015 10:43 PM
You can either create the simple transformation to convert the XML into your data structure. Or else, you would need to loop through the kids of the specific node.
DATA: o_xml_document TYPE REF TO cl_xml_document. DATA: v_tag_value TYPE string. DATA: lo_kid_1 TYPE REF TO if_ixml_node. DATA: lv_name TYPE string, ENDWHILE. |
This sample XML
<?xml version="1.0" encoding="utf-8"?>
<infCarga>
<vCarga>10000.00</vCarga>
<proPred>PNEU</proPred>
<xOutCat>GRANEL</xOutCat>
<infQ>
<cUnid>01</cUnid>
<tpMed>PESO BRUTO</tpMed>
<qCarga>13.0000</qCarga>
</infQ>
<infQ>
<cUnid>03</cUnid>
<tpMed>UNIDADE</tpMed>
<qCarga>500.0000</qCarga>
</infQ>
</infCarga>
Would generate this output
vCarga 10000.00
proPred PNEU
xOutCat GRANEL
cUnid 01
tpMed PESO BRUTO
qCarga 13.0000
cUnid 03
tpMed UNIDADE
qCarga 500.0000
Regards,
Naimesh Patel
07-15-2015 10:43 AM