<?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: iXML - Reading a specific tag/specific attribute in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/ixml-reading-a-specific-tag-specific-attribute/m-p/3411507#M819317</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;setting and getting attribute &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  YXMLATTRIBUTE1.


types: begin of p_type ,
       identity(10),
       end of p_type .
data: l_xml  type ref to cl_xml_document  ,
     if_xml type ref to if_ixml_document ,
     node type ref to if_ixml_node  ,
     rval type string .
data: wa_persons type p_type .
data: xml_out type string .


call transformation id
      source persons = wa_persons
      result xml xml_out.


create object l_xml.

call method l_xml-&amp;gt;parse_string
  exporting
    stream = xml_out.


node = l_xml-&amp;gt;find_node(
    name   = 'IDENTITY'
*    ROOT   = ROOT
       ).

l_xml-&amp;gt;set_attribute(
    name    = 'Name'
    value   = 'Charles'
    node    = node
       ).

l_xml-&amp;gt;set_attribute(
    name    = 'Name2'
    value   = 'Mayer'
    node    = node
       ).
l_xml-&amp;gt;set_attribute(
      name    = 'Job'
      value   = 'Development'
      node    = node
         ).

clear rval .
CALL METHOD l_xml-&amp;gt;find_attribute
  EXPORTING
    node_name = 'IDENTITY'
    attr_name = 'Name'
*    root      =
  receiving
    value     = rval .


call method l_xml-&amp;gt;display.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 16 Feb 2008 07:27:27 GMT</pubDate>
    <dc:creator>athavanraja</dc:creator>
    <dc:date>2008-02-16T07:27:27Z</dc:date>
    <item>
      <title>iXML - Reading a specific tag/specific attribute</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/ixml-reading-a-specific-tag-specific-attribute/m-p/3411506#M819316</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'm trying to get out a specific tag ans specific attribute from an xml string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I built my method based on BCCIIXMLT2 &amp;amp; BCCIIXMLT11 and &lt;A class="jive_macro jive_macro_thread" href="https://community.sap.com/" __jive_macro_name="thread" modifiedtitle="true" __default_attr="194234"&gt;&lt;/A&gt;, however it doesn't seem to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I already tried 2 approach, none of them worked &lt;SPAN __jive_emoticon_name="sad"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The loops are ended before the get_attributes method is called.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;METHOD /eby/if_xml_output_writer~finish_element.

* Based on program BCCIIXMLT2 &amp;amp; BCCIIXMLT11

* \\ ======= iXML =======
  DATA:
    lr_ixml           TYPE REF TO if_ixml,
    lr_xml_doc        TYPE REF TO if_ixml_document,
    lr_node           TYPE REF TO if_ixml_node,
*    lr_iterator       TYPE REF TO if_ixml_inline_iterator,
    lr_iterator       TYPE REF TO if_ixml_node_iterator,
    lr_nodemap        TYPE REF TO if_ixml_named_node_map,
    lr_stream_factory TYPE REF TO if_ixml_stream_factory,
    lr_istream        TYPE REF TO if_ixml_istream,
    lr_parser         TYPE REF TO if_ixml_parser,
    lr_nnmap          TYPE REF TO if_ixml_named_node_map,
    lr_attr           TYPE REF TO if_ixml_node,

    lc_name           TYPE string,
    lc_value          TYPE string,
    lc_prefix         TYPE string,
    li_type           TYPE i,
    li_indent         TYPE i,
    li_index          TYPE i,
    li_count          TYPE i.
* // ======= iXML =======
*=======================================================================
  CLASS     cl_ixml          DEFINITION LOAD.
*=======================================================================

  CHECK i_parent IS INITIAL.

*-- Create the main factory
  lr_ixml = cl_ixml=&amp;gt;create( ).
*-- Create the initial document
  lr_xml_doc = lr_ixml-&amp;gt;create_document( ).
*-- Create the stream factory
  lr_stream_factory = lr_ixml-&amp;gt;create_stream_factory( ).
*-- Create a stream for the input (string)
  lr_istream = lr_stream_factory-&amp;gt;create_istream_cstring( i_input ).
*-- Create the parser
 lr_parser = lr_ixml-&amp;gt;create_parser( stream_factory = lr_stream_factory
                                     istream        = lr_istream
                                     document       = lr_xml_doc ).
*-- We don't need the stream any more, so let's close it...
  lr_istream-&amp;gt;close( ).

* 1st attempt
*  lr_node = lr_xml_doc.
*  lr_iterator = lr_node-&amp;gt;create_inline_iterator( ).
*  li_type     = lr_iterator-&amp;gt;get_type( ).
*
*  WHILE li_type NE 0.
*    li_indent = lr_iterator-&amp;gt;get_height( ) * 2.
*
*    CASE li_type.
*      WHEN if_ixml_node=&amp;gt;co_node_element.
*
*        lr_nnmap = lr_iterator-&amp;gt;get_attributes( ).
*        li_index = 0.
*        li_count  = lr_nnmap-&amp;gt;get_length( ).
*
*        WHILE li_index &amp;lt; li_count.
*
*          lr_attr  = lr_nnmap-&amp;gt;get_item( li_index ).
*          lc_name  = lr_attr-&amp;gt;get_name( ).
*          lc_value = lr_attr-&amp;gt;get_value( ).
*
*          li_index = li_index + 1.
*        ENDWHILE.
*
*    ENDCASE.
*    li_type = lr_iterator-&amp;gt;advance( ).
*  ENDWHILE.

* 2nd attempt

  lr_node ?= lr_xml_doc.
* Create a node iterator
  lr_iterator = lr_node-&amp;gt;create_iterator( ).
* Get current node
  lr_node = lr_iterator-&amp;gt;get_next( ).

* Loop over all nodes
  WHILE NOT lr_node IS INITIAL.

    li_indent = lr_node-&amp;gt;get_height( ) * 2.
    li_indent = li_indent + 20.

    CASE lr_node-&amp;gt;get_type( ).

      WHEN if_ixml_node=&amp;gt;co_node_element.

*       Element node
        lc_name = lr_node-&amp;gt;get_name( ).
        lr_nodemap = lr_node-&amp;gt;get_attributes( ).

        IF NOT lr_nodemap IS INITIAL.

*         Attributes
          li_count = lr_nodemap-&amp;gt;get_length( ).

          DO li_count TIMES.
            li_index  = sy-index - 1.
            lr_attr   = lr_nodemap-&amp;gt;get_item( li_index ).
            lc_name   = lr_attr-&amp;gt;get_name( ).
            lc_prefix = lr_attr-&amp;gt;get_namespace_prefix( ).
            lc_value  = lr_attr-&amp;gt;get_value( ).
          ENDDO.

        ENDIF.

      WHEN if_ixml_node=&amp;gt;co_node_text OR
           if_ixml_node=&amp;gt;co_node_cdata_section.

*       Text node
        lc_value = lr_node-&amp;gt;get_value( ).

    ENDCASE.

*   Advance to next node
    lr_node = lr_iterator-&amp;gt;get_next( ).

  ENDWHILE.



ENDMETHOD.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any idea what could be wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Feb 2008 14:13:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/ixml-reading-a-specific-tag-specific-attribute/m-p/3411506#M819316</guid>
      <dc:creator>Peter_Inotai</dc:creator>
      <dc:date>2008-02-15T14:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: iXML - Reading a specific tag/specific attribute</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/ixml-reading-a-specific-tag-specific-attribute/m-p/3411507#M819317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;setting and getting attribute &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  YXMLATTRIBUTE1.


types: begin of p_type ,
       identity(10),
       end of p_type .
data: l_xml  type ref to cl_xml_document  ,
     if_xml type ref to if_ixml_document ,
     node type ref to if_ixml_node  ,
     rval type string .
data: wa_persons type p_type .
data: xml_out type string .


call transformation id
      source persons = wa_persons
      result xml xml_out.


create object l_xml.

call method l_xml-&amp;gt;parse_string
  exporting
    stream = xml_out.


node = l_xml-&amp;gt;find_node(
    name   = 'IDENTITY'
*    ROOT   = ROOT
       ).

l_xml-&amp;gt;set_attribute(
    name    = 'Name'
    value   = 'Charles'
    node    = node
       ).

l_xml-&amp;gt;set_attribute(
    name    = 'Name2'
    value   = 'Mayer'
    node    = node
       ).
l_xml-&amp;gt;set_attribute(
      name    = 'Job'
      value   = 'Development'
      node    = node
         ).

clear rval .
CALL METHOD l_xml-&amp;gt;find_attribute
  EXPORTING
    node_name = 'IDENTITY'
    attr_name = 'Name'
*    root      =
  receiving
    value     = rval .


call method l_xml-&amp;gt;display.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Feb 2008 07:27:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/ixml-reading-a-specific-tag-specific-attribute/m-p/3411507#M819317</guid>
      <dc:creator>athavanraja</dc:creator>
      <dc:date>2008-02-16T07:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: iXML - Reading a specific tag/specific attribute</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/ixml-reading-a-specific-tag-specific-attribute/m-p/3411508#M819318</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately my code should also work on 46C, so XLST is not an option. Anyway I used some code from SAPLink  and it works fine now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*-- Create the main factory
  lr_ixml = cl_ixml=&amp;gt;create( ).
*-- Create the initial document
  lr_xml_doc = lr_ixml-&amp;gt;create_document( ).
*-- Create the stream factory
  lr_stream_factory = lr_ixml-&amp;gt;create_stream_factory( ).
*-- Create a stream for the input (string)
  lr_istream = lr_stream_factory-&amp;gt;create_istream_cstring( i_input ).
*-- Create the parser
  lr_parser = lr_ixml-&amp;gt;create_parser(
                      stream_factory = lr_stream_factory
                      istream        = lr_istream
                      document       = lr_xml_doc ).
*-- Parse the stream
  lr_parser-&amp;gt;parse( ).
*-- We don't need the stream any more, so let's close it...
  CLEAR lr_istream.

* Find the tag
  lr_rootnode = lr_xml_doc-&amp;gt;find_from_name( c_tag_structureddocument ).


  lr_attributelist = lr_rootnode-&amp;gt;get_attributes( ).
  lr_nodeiterator  = lr_attributelist-&amp;gt;create_iterator( ).
  lr_attributenode = lr_nodeiterator-&amp;gt;get_next( ).

* Find the attribute
  WHILE lr_attributenode IS NOT INITIAL.
    lc_name = lr_attributenode-&amp;gt;get_name( ).
    IF lc_name = c_attribute_id.
      lc_value = lr_attributenode-&amp;gt;get_value( ).
      EXIT.
    ENDIF.
    lr_attributenode = lr_nodeiterator-&amp;gt;get_next( ).
  ENDWHILE.

  mc_output = lc_value.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Feb 2008 09:02:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/ixml-reading-a-specific-tag-specific-attribute/m-p/3411508#M819318</guid>
      <dc:creator>Peter_Inotai</dc:creator>
      <dc:date>2008-02-18T09:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: iXML - Reading a specific tag/specific attribute</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/ixml-reading-a-specific-tag-specific-attribute/m-p/3411509#M819319</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;I have a related query for CL_XML_DOCUMENT and IF_IXML_NODE classes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to treat a node if its an internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I use CALL TRANSFORMATION id to convert a deep strcuture into XML document. and traverse it using iterator. If the iterator-&amp;gt;get_next( ) is an intenal table in the deep structure then i need to read/write the records. HOw do we do this ?&lt;/P&gt;&lt;P&gt;If its a flat field then GET_VALUE and SET_VALUES methods works fine but it fails in case of an Internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Appreciate your thoughts here.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Nilesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jan 2015 11:15:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/ixml-reading-a-specific-tag-specific-attribute/m-p/3411509#M819319</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-01-21T11:15:18Z</dc:date>
    </item>
  </channel>
</rss>

