<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: XML - DOM in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/xml-dom/m-p/3017289#M713141</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Krishnan Venkataraman  ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;check the following thread :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_message" href="https://community.sap.com/" __jive_macro_name="message" modifiedtitle="true" __default_attr="4417845"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers!&lt;/P&gt;&lt;P&gt;gyanaraj&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;****Pls reward points if u find this helpful&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 12 Nov 2007 13:03:43 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-11-12T13:03:43Z</dc:date>
    <item>
      <title>XML - DOM</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/xml-dom/m-p/3017287#M713139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using DOM method to parse the XML file.  It is working fine.  But in some cases I need to get type value also in a node.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example consider a node....&lt;/P&gt;&lt;P&gt;&amp;lt;nodexx type="zzzzzz"&amp;gt; yyyyy &amp;lt;/nodexx&amp;gt;.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case I am able to get the node name (nodexx in the above sample) using method get_name( ) and the value (yyyyy in the above sample) using method get_value( ).  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I get the value of the type mentioned in the xml which is zzzzzz.  (I tried checking the method get_type() but in this case it is a custom value)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Krish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Nov 2007 01:30:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/xml-dom/m-p/3017287#M713139</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-12T01:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: XML - DOM</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/xml-dom/m-p/3017288#M713140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Krishan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps the sample report &amp;lt;b&amp;gt;T_PARSING_DOM&amp;lt;/b&amp;gt; (package &amp;lt;b&amp;gt;SIXML_TEST&amp;lt;/b&amp;gt;) may be helpful for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Report  T_DOM_PARSING                                               *
*&amp;amp;                                                                     *
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Shows xml DOM parsing using the iXML DOM parser                     *
*&amp;amp;                                                                     *
*&amp;amp;---------------------------------------------------------------------*
REPORT t_dom_parsing  LINE-SIZE 512.
SET EXTENDED CHECK OFF.

*************************************************************
* macros
*
DEFINE xml.
  concatenate xmldata &amp;amp;1 into xmldata.
  write: / 'XML:', &amp;amp;1 color col_positive inverse.
END-OF-DEFINITION.

*************************************************************
* global data
*
DATA: ixml            TYPE REF TO if_ixml,
      streamfactory   TYPE REF TO if_ixml_stream_factory,
      parser          TYPE REF TO if_ixml_parser,
      istream         TYPE REF TO if_ixml_istream,
      document        TYPE REF TO if_ixml_document,
      node            TYPE REF TO if_ixml_node,
      xmldata         TYPE string.


*************************************************************
* xml document
*
START-OF-SELECTION.
  WRITE: /.
  WRITE: / 'XML-Document to parse'.
  WRITE: /.
  xml '&amp;lt;?xml version="1.0"?&amp;gt;'.
  xml '&amp;lt;order number="4711"&amp;gt;'.
  xml '   &amp;lt;head&amp;gt;'.
  xml '     &amp;lt;status&amp;gt;confirmed&amp;lt;/status&amp;gt;'.
  xml '     &amp;lt;date format="mm/dd/yyyy"&amp;gt;08/15/1999&amp;lt;/date&amp;gt;'.
  xml '   &amp;lt;/head&amp;gt;'.
  xml '   &amp;lt;body&amp;gt;'.
  xml '     &amp;lt;item pos="10" units="2" price="17"&amp;gt;abap-book  &amp;lt;/item&amp;gt;'.
  xml '     &amp;lt;item pos="20" units="1" price="10"&amp;gt;sapr3-cdrom&amp;lt;/item&amp;gt;'.
  xml '     &amp;lt;item pos="30" units="5" price="12"&amp;gt;coffee     &amp;lt;/item&amp;gt;'.
  xml '   &amp;lt;/body&amp;gt;'.
  xml '&amp;lt;/order&amp;gt;'.

*************************************************************
* xml partsing preparation
*

* create the ixml main factory
  ixml = cl_ixml=&amp;gt;create( ).

* create a stream factory
  streamfactory = ixml-&amp;gt;create_stream_factory( ).

* create a input stream
  istream  = streamfactory-&amp;gt;create_istream_string( string = xmldata ).

* create a ixml document
  document = ixml-&amp;gt;create_document( ).

* create a xml parser
  parser  = ixml-&amp;gt;create_parser( document       = document
                                 stream_factory = streamfactory
                                 istream        = istream ).

* parse the xml document into DOM tree
  IF parser-&amp;gt;parse( ) &amp;lt;&amp;gt; 0.
    PERFORM process_errors USING parser.
    EXIT.
  ELSE.
    node ?= document.
    PERFORM print_dom USING node.
  ENDIF.



*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  process_errors
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      --&amp;gt;P_PARSER  text
*----------------------------------------------------------------------*
FORM process_errors  USING p_parser TYPE REF TO if_ixml_parser.
  DATA: error  TYPE REF TO if_ixml_parse_error,
        msg    TYPE string,
        count  TYPE i,
        index  TYPE i,
        off    TYPE i.

  WRITE: /.
  WRITE: / 'PARSER-ERRORS'.

  count = p_parser-&amp;gt;num_errors( min_severity = if_ixml_parse_error=&amp;gt;co_warning ).
  CHECK count &amp;lt;&amp;gt; 0.
* write error messages
  DO count TIMES.
    index  = sy-index - 1.
    error  = p_parser-&amp;gt;get_error( index = index
                                  min_severity = if_ixml_parse_error=&amp;gt;co_warning ).
    msg    = error-&amp;gt;get_reason( ).
    off    = error-&amp;gt;get_offset( ).
    if error-&amp;gt;get_severity( ) = if_ixml_parse_error=&amp;gt;co_warning.
       WRITE: / 'warn :', msg COLOR COL_GROUP    INVERSE, off.
    else.
       WRITE: / 'error:', msg COLOR COL_NEGATIVE INVERSE, off.
    endif.
  ENDDO.
ENDFORM.                    " process_errors
*---------------------------------------------------------------------*
*       FORM print_tree                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM print_dom USING node TYPE REF TO if_ixml_node.
  DATA: iterator  TYPE REF TO if_ixml_node_iterator,
        nodemap   TYPE REF TO if_ixml_named_node_map,
        attr      TYPE REF TO if_ixml_node,
        name      TYPE string,
        prefix    TYPE string,
        value     TYPE string,
        indent    TYPE i,
        count     TYPE i,
        index     TYPE i.

  CHECK NOT node IS INITIAL.

  ULINE.
  WRITE: /.
  WRITE: /' DOM-TREE'.
  WRITE: /.
  IF node IS INITIAL. EXIT. ENDIF.
* create a node iterator
  iterator  = node-&amp;gt;create_iterator( ).
* get current node
  node = iterator-&amp;gt;get_next( ).

* loop over all nodes
  WHILE NOT node IS INITIAL.
    indent = node-&amp;gt;get_height( ) * 2.
    indent = indent + 20.

    CASE node-&amp;gt;get_type( ).
      WHEN if_ixml_node=&amp;gt;co_node_element.
*       element node
        name    = node-&amp;gt;get_name( ).
        nodemap = node-&amp;gt;get_attributes( ).
        WRITE: / 'ELEMENT  :'.
        WRITE: AT indent name COLOR COL_POSITIVE INVERSE.
        IF NOT nodemap IS INITIAL.
*         attributes
          count = nodemap-&amp;gt;get_length( ).
          DO count TIMES.
            index  = sy-index - 1.
            attr   = nodemap-&amp;gt;get_item( index ).
            name   = attr-&amp;gt;get_name( ).
            prefix = attr-&amp;gt;get_namespace_prefix( ).
            value  = attr-&amp;gt;get_value( ).
            WRITE: / 'ATTRIBUTE:'.
            WRITE: AT indent name  COLOR COL_HEADING INVERSE, '=',
                             value COLOR COL_TOTAL   INVERSE.
          ENDDO.
        ENDIF.
      WHEN if_ixml_node=&amp;gt;co_node_text or
           if_ixml_node=&amp;gt;co_node_cdata_section.
*       text node
        value  = node-&amp;gt;get_value( ).
        WRITE: / 'TEXT     :'.
        WRITE: AT indent value COLOR COL_GROUP INVERSE.
    ENDCASE.
*   advance to next node
    node = iterator-&amp;gt;get_next( ).
  ENDWHILE.
ENDFORM.                    "traverse_dom&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Nov 2007 04:51:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/xml-dom/m-p/3017288#M713140</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2007-11-12T04:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: XML - DOM</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/xml-dom/m-p/3017289#M713141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Krishnan Venkataraman  ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;check the following thread :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_message" href="https://community.sap.com/" __jive_macro_name="message" modifiedtitle="true" __default_attr="4417845"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;cheers!&lt;/P&gt;&lt;P&gt;gyanaraj&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;****Pls reward points if u find this helpful&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Nov 2007 13:03:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/xml-dom/m-p/3017289#M713141</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-12T13:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: XML - DOM</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/xml-dom/m-p/3017290#M713142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks guys.. I got the type under attributes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Krish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Nov 2007 16:20:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/xml-dom/m-p/3017290#M713142</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-12T16:20:57Z</dc:date>
    </item>
  </channel>
</rss>

