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

Problem in parsing white spaces using if_ixml_parser

Former Member
0 Likes
1,148

Hello People,

I have a problem in parsing XML file in one of my programs.

The program uses the method get_value( ) of class if_ixml_node to fetch a value. In the XML file when the value is spaceA, then after parsing, the value fetched is A and not spaceA.

Is there any way to fetch the white spaces also?

Here is the sample tag. The value inside the tags is " A" and after parsing I get "A" the blank is ignored.

<ns1:IndiceCible> A</ns1:IndiceCible>

DATA : l_node_fils TYPE REF TO if_ixml_node.

indice_val = l_node_fils->get_value( ).

In some XML parsing forums I saw that if we add the option as shown below, then the parsing works properly. But this did not work in my case.

<ns1:IndiceCible xml:space="preserve"> A</ns1:IndiceCible>

The input XML file is as follows.

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><env:Flow xmlns:env="http://xml.inetpsa.com/Structure/Informatique/DeveloppementSI/ReferentielEchange"><env:MessageID>0414

2636F4888F4B4A579A21E10000000A52931C</env:MessageID><env:From>R3P INTERFACES</env:From><env:To>SAP</env:To><env:TimeStamp>2010-03-04T14:26:36.672+01:00</env:TimeStamp></env:Flow></SOAP-ENV:Header><SOAP-ENV:Body><env:Response xmlns:env="http://xml.inetpsa.

com/Structure/Informatique/DeveloppementSI/ReferentielEchange"><env:Values><ns1:ListeTranscodifications xmlns:ns1="http://xml.inetpsa.com/ProduitProcess/Produit/Transcodification"><ns1:Transcodification id="1 "><ns1:Statut>KO</ns1:Statut><ns1:Message>ERRO

R : Indice incorrect</ns1:Message><ns1:ReferenceCible>969099979A</ns1:ReferenceCible><ns1:IndiceCible> A</ns1:IndiceCible><ns1:ColoreCible>SS_TEINTE</ns1:ColoreCible></ns1:Transcodification></ns1:ListeTranscodifications></env:Values><env:Status><env:Code>

0</env:Code><env:Label></env:Label></env:Status></env:Response></SOAP-ENV:Body></SOAP-ENV:Envelope>

Regards,

Praveen

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
838

use IF_XML_PARSER~CL_ADD_PRESERVE_SPACE_ELEMENT method:


PARAMETERS preserve TYPE flag AS checkbox.
  DATA lo_ixml          TYPE REF TO if_ixml.
  DATA lo_streamfactory TYPE REF TO if_ixml_stream_factory.
  DATA lo_parser        TYPE REF TO if_ixml_parser.
  DATA lo_istream       TYPE REF TO if_ixml_istream.
  DATA lo_document      TYPE REF TO if_ixml_document.
  DATA lo_node          TYPE REF TO if_ixml_node.
  DATA l_node_value          TYPE string.
  lo_ixml = cl_ixml=>create( ).
  lo_streamfactory = lo_ixml->create_stream_factory( ).
  lo_istream = lo_streamfactory->create_istream_string(
        string = '<?xml version="1.0" encoding="iso-8859-1"?><DATA>  WAAA</DATA>' ).
  lo_document = lo_ixml->create_document( ).
  lo_parser = lo_ixml->create_parser( stream_factory = lo_streamfactory
                                      istream        = lo_istream
                                      document       = lo_document ).
IF preserve = 'X'.
  lo_parser->ADD_PRESERVE_SPACE_ELEMENT( ). "<========= HERE
ENDIF.
  lo_parser->parse( ).
  lo_node = lo_document->find_from_name( name = 'DATA').
  l_node_value = lo_node->get_value( ).
  ASSERT ( preserve = 'X' AND l_node_value = '  WAAA' )
        OR ( preserve = space AND l_node_value = 'WAAA' ).

Hello People,

I have a problem in parsing XML file in one of my programs.

The program uses the method get_value( ) of class if_ixml_node to fetch a value. In the XML file when the value is spaceA, then after parsing, the value fetched is A and not spaceA.

Is there any way to fetch the white spaces also?

Here is the sample tag. The value inside the tags is " A" and after parsing I get "A" the blank is ignored.

<ns1:IndiceCible> A</ns1:IndiceCible>

DATA : l_node_fils TYPE REF TO if_ixml_node.

indice_val = l_node_fils->get_value( ).

In some XML parsing forums I saw that if we add the option as shown below, then the parsing works properly. But this did not work in my case.

<ns1:IndiceCible xml:space="preserve"> A</ns1:IndiceCible>

The input XML file is as follows.

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><env:Flow xmlns:env="http://xml.inetpsa.com/Structure/Informatique/DeveloppementSI/ReferentielEchange"><env:MessageID>0414

2636F4888F4B4A579A21E10000000A52931C</env:MessageID><env:From>R3P INTERFACES</env:From><env:To>SAP</env:To><env:TimeStamp>2010-03-04T14:26:36.672+01:00</env:TimeStamp></env:Flow></SOAP-ENV:Header><SOAP-ENV:Body><env:Response xmlns:env="http://xml.inetpsa.

com/Structure/Informatique/DeveloppementSI/ReferentielEchange"><env:Values><ns1:ListeTranscodifications xmlns:ns1="http://xml.inetpsa.com/ProduitProcess/Produit/Transcodification"><ns1:Transcodification id="1 "><ns1:Statut>KO</ns1:Statut><ns1:Message>ERRO

R : Indice incorrect</ns1:Message><ns1:ReferenceCible>969099979A</ns1:ReferenceCible><ns1:IndiceCible> A</ns1:IndiceCible><ns1:ColoreCible>SS_TEINTE</ns1:ColoreCible></ns1:Transcodification></ns1:ListeTranscodifications></env:Values><env:Status><env:Code>

0</env:Code><env:Label></env:Label></env:Status></env:Response></SOAP-ENV:Body></SOAP-ENV:Envelope>

Regards,

Praveen

1 REPLY 1
Read only

Sandra_Rossi
Active Contributor
839

use IF_XML_PARSER~CL_ADD_PRESERVE_SPACE_ELEMENT method:


PARAMETERS preserve TYPE flag AS checkbox.
  DATA lo_ixml          TYPE REF TO if_ixml.
  DATA lo_streamfactory TYPE REF TO if_ixml_stream_factory.
  DATA lo_parser        TYPE REF TO if_ixml_parser.
  DATA lo_istream       TYPE REF TO if_ixml_istream.
  DATA lo_document      TYPE REF TO if_ixml_document.
  DATA lo_node          TYPE REF TO if_ixml_node.
  DATA l_node_value          TYPE string.
  lo_ixml = cl_ixml=>create( ).
  lo_streamfactory = lo_ixml->create_stream_factory( ).
  lo_istream = lo_streamfactory->create_istream_string(
        string = '<?xml version="1.0" encoding="iso-8859-1"?><DATA>  WAAA</DATA>' ).
  lo_document = lo_ixml->create_document( ).
  lo_parser = lo_ixml->create_parser( stream_factory = lo_streamfactory
                                      istream        = lo_istream
                                      document       = lo_document ).
IF preserve = 'X'.
  lo_parser->ADD_PRESERVE_SPACE_ELEMENT( ). "<========= HERE
ENDIF.
  lo_parser->parse( ).
  lo_node = lo_document->find_from_name( name = 'DATA').
  l_node_value = lo_node->get_value( ).
  ASSERT ( preserve = 'X' AND l_node_value = '  WAAA' )
        OR ( preserve = space AND l_node_value = 'WAAA' ).