XML element attributes in program

I am using following FMs to create XML document from internal table
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
CALL FUNCTION 'SDIXML_DOM_TO_XML'
My internal table has field 'AMT' and generated XML file has following line
<AMT>1000</AMT>
But I want this line to be generated as <AMT Ccy = 'USD'>1000</AMT>
I tried to use set_attribute method of element but not able to get this.I should be missing somethig as I am new to this XML.
Can anyone please advsie how I can get this?
Thanks for your help.
Srinivas

Hello Srinivas
Below you see sample coding that I use on SAP-PI to map attributes into the XML stream (INVOIC IDoc)::
NOTE: mo_document is of TYPE REF TO if_ixml_document (which is exported as DATA_AS_DOM by fm SDIXML_DATA_TO_DOM).
METHOD MAP_SD_DOC_CAT_AND_BILL_TYPE.
* define local data
  DATA: ld_billingdoc         TYPE bapivbrkout-billingdoc,
        ld_billing_type       type bapivbrkout-bill_type,
        ld_sd_doc_category    TYPE vbtyp,
        ld_edi_qualifier      TYPE string.
  " Location code mapping only for outbound invoices, i.e.
  " invoices sent by subsidiary to its customers
  CHECK ( is_outbound_invoic( ) = abap_true ).
  CALL METHOD zcl_edi_idoc_invoic_services=>get_billingdoc_detail
    EXPORTING
      param              = mif_param
*      id_idocnumber      =
      id_rfc_destination = md_rfcdest
    IMPORTING
      ed_billingdoc      = ld_billingdoc
      ed_billing_type    = ld_billing_type
      ed_sd_doc_category = ld_sd_doc_category
      ed_edi_qualifier   = ld_edi_qualifier.
* NOTE: We add the SD document category and the EDI qualifier
*       as attributes to E1EDK01/BELNR.
**  <E1EDK01 SEGMENT="1">
**      <CURCY>EUR</CURCY>
**      <HWAER>EUR</HWAER>
**      <WKURS>1.00000</WKURS>
**      <ZTERM>T60F</ZTERM>
**      <EIGENUINR>nnn</EIGENUINR>
**      <BSART>INVO</BSART>
**      <BELNR SD_DOC_CATEGORY="O" EDI_QUALIFIER="381" BILL_TYPE="ZOII">
**        1010010911
**      </BELNR>
**      <NTGEW>97.662</NTGEW>
**      <BRGEW>127.239</BRGEW>
**      <GEWEI>KGM</GEWEI>
**      <FKART_RL>LR</FKART_RL>
**      <RECIPNT_NO>0000823305</RECIPNT_NO>
**      <FKTYP>L</FKTYP>
**  </E1EDK01>
  DATA: ld_name       TYPE string,
        ld_value      TYPE string,
        ld_rc         TYPE i,
        lo_node       TYPE REF TO if_ixml_node,
        lo_node_child TYPE REF TO if_ixml_node,
        lo_clone      TYPE REF TO if_ixml_node,
        lo_children   TYPE REF TO if_ixml_node_list,
        lo_element    TYPE REF TO if_ixml_element,
        lo_attribute  TYPE REF TO if_ixml_attribute,
        lo_filter     TYPE REF TO if_ixml_node_filter,
        lo_iter       TYPE REF TO if_ixml_node_iterator,
        lo_doc        TYPE REF TO if_ixml_document.
* Filter for nodes of segment E1EDK01
  lo_filter = mo_document->create_filter_name( name = 'E1EDK01' ).
  CALL METHOD mo_document->create_iterator_filtered
    EXPORTING
*      depth  = 0
      filter = lo_filter
    RECEIVING
      rval   = lo_iter.
  DO.
    lo_node = lo_iter->get_next( ).
    EXIT.
  ENDDO.
* NODE: First (and single) parent node is the entire E1EDK01 segment
  lo_children = lo_node->get_children( ).
  lo_filter = mo_document->create_filter_name( name = 'BELNR' ).
  lo_iter = lo_children->create_iterator_filtered( lo_filter ).
* NOTE: We should have a single child node => BELNR
  DO.
    lo_node = lo_iter->get_next( ).
    EXIT.
  ENDDO.
  CHECK ( lo_node IS BOUND ).
  ld_name  = lo_node->get_name( ).
  ld_value = lo_node->get_value( ).
  LOG-POINT ID zedi
                  SUBKEY mc_subkey_runtime
                  FIELDS syst-index ld_name ld_value.
* Add attribute SD_DOC_CATEGORY and EDI_QUALIFIER to element BELNR
  lo_element ?= lo_node.
  ld_name  = 'SD_DOC_CATEGORY'.
  ld_value = ld_sd_doc_category.
  CALL METHOD lo_element->set_attribute
    EXPORTING
      name  = ld_name
      value = ld_value
    RECEIVING
      rval  = ld_rc.
  ld_name  = 'EDI_QUALIFIER'.
  ld_value = ld_edi_qualifier.
  CALL METHOD lo_element->set_attribute
    EXPORTING
      name  = ld_name
      value = ld_value
    RECEIVING
      rval  = ld_rc.
  ld_name  = 'BILL_TYPE'.
  ld_value = ld_billing_type.
  CALL METHOD lo_element->set_attribute
    EXPORTING
      name  = ld_name
      value = ld_value
    RECEIVING
      rval  = ld_rc.
ENDMETHOD.
Regards
  Uwe

Similar Messages

  • Pixel-Positions in XML-Element attributes

    hi,
    is there a way, when attaching a xml-tag to e.g. a picture, that the top and left pixel value is saved in a xml-element attribute? the pixel value from top and from the left.
    thanks in advance.
    regards.

    hi,
    is there a way, when attaching a xml-tag to e.g. a picture, that the top and left pixel value is saved in a xml-element attribute? the pixel value from top and from the left.
    thanks in advance.
    regards.

  • JS: how can find role in XML element attribute

    Dear All,
    We could gather "footnote" XML elements as an array. But we need to filter the elements which has "role=endnote" in the attributes from the group of common footnote tagged elements .
    Eg. <footnote xml:id="en2" label="2" role="endnote"> from myGetXMLElements("//footnote")
    Kindly assist to get footnote XML elements which has the role "endnote".
    regards
    Masthan

    Hi Fred,
    Yes, I got it. Thanks
    regards
    Masthan

  • XML Gateway Mapping of XML Element Attribute

    Hi:
    If an inbound XML message contains this tag:
    <STATUS CODE="100"></STATUS>
    is it possible to map the CODE attribute to a database column?
    I've been attempting to do this but I'm receiving this error: Element STATUS not complete, expected elements ''.
    Thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I'll answer my own question here.  Found the section in the XML User Guide about mapping HTTP Error Responses (chapter 22 in the v6.1 pdf) and realized that the XML gateway had preconfigured settings to handle various error conditions.  Edited the error handling configuration for the specific Handler (rather than the global setting) and checked the box to allow the error to pass through the XML gateway.  Redeployed the subpolicy.

  • Reading XML element attribute

    I use JSTL to read a remote XML but can only print the content of the elements. How do i print the content of the attributes?
    <root><person id="1">George</person></root>
    For example, to read the Person's name i use:
    <x:out select="$xmloutput/ROOT/person"/>
    But how do i print the ID value of the element?
    Thanks in advance.

    Already found the answer:
    <x:out select="@attribute_name" />
    Just add the @ sign

  • Parse XML Elements/Attributes from CLOB into Oracle Table

    Hi!
    I have an XML file (loaded into a CLOB) which I need to parse and have each individual element and attribute inserted into an oracle table for manipulation.
    Eg: XML File...
    <PERSON>
    <PER_ID changed="1">1</PER_ID>
    <SURNAME changed="1">MARTIN</SURNAME>
    <ADDRESS>
    <STREET_NO changed="1">1</STREET_NO>
    <POSTCODE changed="1">LE3 8RA</POSTCODE>
    </ADDRESS>
    </PERSON>
    There will only ever be one address.
    From this I need to extract
    * PER_ID and related changed attribute
    * SURNAME and related changed attribute
    * STREET_NO and related changed attribute
    * POSTCODE and related changed attribute
    and insert a single record into the table below:
    CREATE TABLE PERSON AS
    ( PER_ID VARCHAR2(10)
    , ID_CHANGED VARCHAR2(1)
    , SURNAME VARCHAR2(30)
    , ID_CHANGED VARCHAR2(1)
    , STREET_NO VARCHAR2(5)
    , ID_CHANGED VARCHAR2(1)
    , POSTCODE VARCHAR2(10) );
    Any assistance/advice would be very much appreciated. I've tried using DBMS_XMLSave / DBMS_XMLStore which works great at pulling in elements (PER_ID, SURNAME, etc) straight into the table but doesn't look at the changed attributes, and I need both.
    Thanks a million in advance to anyone who can crack this!!
    Jay

    Try looking at this thread
    Loading datafrom a PL/SQL table into the Database table

  • Replacing harcoded XML element attributes with variables

    Is there any way for Xpath expressions in JAVA to refer to variables (for an attribute) instead of harcoded strings (like 'abc' and 'xyz' below)
    So below ... 'abc' , 'xyz' could be varaibles.....
    String getServerInstance="/Accounts/Account[@code='abc']/TestingProgram[@code='abc']/Modes/Mode[@code='xyz']/*";
    Thanks a lot

    I have a class now that resolves variables:
    public class Resolve_Xpath_Vars implements XPathVariableResolver
         public Object resolveVariable(QName var)
    try {          
              if (var.equals(new QName("pqr")))
                        return new String("pqr");
              else if (var.equals(new QName("abcde")))
                        return new String("abcde");
    else
    return null;
    catch (Exception ex)
              ex.printStackTrace();
              throw new RuntimeException();     
    NOWWWWW
    how do i configure my XPATH expression to call this class to reolve my varaible....
    XPATH EXPRESSION IS:
    "this.Account" is the variable that the class should resolve.....to "pqr"
    String getAccnt="/Accounts/Account[@code="+"'"+*this.Account*+"'"+"]/*";      
    Once resolved to "pqr" then i can make the following call:
    NodeList nodeList =(NodeList) xPath.evaluate(getAccnt, inputSource, XPathConstants.NODESET );
    any help is appreciated.............

  • Parse XML Elements/Attributes from CLOB in PL/SQL

    Hi folks,
    I'm new to XML development in Oracle...I need some help in Parsing a XML stored in a CLOB column using PL/SQL.
    We are using Oracle 9i R2. Do i need install the XDK and /or XML DB?
    Basically the xml has some quiz questions and the answers to the quiz. Once student submits the quiz we need parse the XML and calculate the grade.
    Any help is appreciated...
    Thanks,

    A bit dirty but this works:
    Create an XMLType based on the CLOB contents...
    select extractvalue(value(x), '/PERSON/PER_ID/text()') PER_ID, extractvalue(value(x), '/PERSON/PER_ID/@changed') PER_ID_CHG
    , extractvalue(value(x), '/PERSON/SURNAME/text()') PER_SURNAME, extractvalue(value(x), '/PERSON/SURNAME/@changed') PER_SURNAME_CHG
    , extractvalue(value(x), '/PERSON/ADDRESS/STREET_NO/text()') PER_STREET_NO, extractvalue(value(x), '/PERSON/ADDRESS/STREET_NO/@changed') PER_STREET_NO_CHG
    , extractvalue(value(x), '/PERSON/ADDRESS/POSTCODE/text()') PER_POSTCODE, extractvalue(value(x), '/PERSON/ADDRESS/POSTCODE/@changed') PER_POSTCODE_CHG
    from table(xmlsequence(extract(xmltype('
    <PERSON>
    <PER_ID changed="1">260180</PER_ID>
    <SURNAME changed="2">MARTIN</SURNAME>
    <ADDRESS>
    <STREET_NO changed="3">1</STREET_NO>
    <POSTCODE changed="4">LE3 8RA</POSTCODE>
    </ADDRESS>
    </PERSON>')
    , 'PERSON')
    ) x;

  • Need to replace/modify an element attribute

    Hi,
    I need to read an XML file and modify the value of an XML element attribute and write the modified element back to the file. This element is two levels deep in the heirarchy,
    currently i am reading all the children and modifying the value of this particular attribue and writing all the children back.
    Does anybody know of a method where we can do a replace operation on the Document rather than the lengthy process that i am currrently using??
    Thanks

    you might want to look at STX streaming transforms-
    http://www.xml.com/pub/a/2003/02/26/stx.html
    That seems a good match for a simple replace problem.
    Pete

  • [JS-CS4] - How to read the XML Element and its Attributes

    Dear All,
      I have the doubt regarding: reading the xmlElement and its attributes.
    Here I droping the xml script
    //============= Start ======================//
    var myDoc = app.activeDocument;
    var Fpath = File("../Projects/Entity_map.xml");
      if (Fpath.exists)
       Fpath.open("r");
       var Cont= Fpath.read();
      var roots = new XML(Cont);
      var myEveryName = new Array();
      var myEveryContent = new Array();
      var myEveryAttributes = new Array();
      traverse(roots);
    //$.writeln(myEveryName);
    //$.writeln(myEveryContent);
    $.writeln(myEveryAttributes.length);
    for(var i=0; i<myEveryAttributes.length; i++)
      $.writeln(myEveryAttributes[i]);
    function traverse(tree) {
        myEveryName.push(tree.name());
    myEveryContent.push(tree.text());
      myEveryAttributes.push(tree.getAttribute);
    // you get the contents by using .text() insted of .name()
        if(tree.elements().length() > 0) {
            for(var i=0; i<tree.elements().length(); i++) {
                traverse(tree.elements()[i]);
    //============== End =====================//
    and the XML Structure is
    //===============XML =====================//
    <?xml version="1.0" encoding="UTF-8"?>< Entity_Convertion>
    < Entitys char="Ç" GID="173"/></ 
    Entity_Convertion>
    //===============End ====================//
    Here I'm getting the XML Elements and its contents, but not xmlAttributes.
    Please any one can help me, then I will appreciate...
    Thanks & Regards
    T.R.Harihara SudhaN

    Dear All,
      I have the doubt regarding: reading the xmlElement and its attributes.
    Here I droping the xml script
    //============= Start ======================//
    var myDoc = app.activeDocument;
    var Fpath = File("../Projects/Entity_map.xml");
      if (Fpath.exists)
       Fpath.open("r");
       var Cont= Fpath.read();
      var roots = new XML(Cont);
      var myEveryName = new Array();
      var myEveryContent = new Array();
      var myEveryAttributes = new Array();
      traverse(roots);
    //$.writeln(myEveryName);
    //$.writeln(myEveryContent);
    $.writeln(myEveryAttributes.length);
    for(var i=0; i<myEveryAttributes.length; i++)
      $.writeln(myEveryAttributes[i]);
    function traverse(tree) {
        myEveryName.push(tree.name());
    myEveryContent.push(tree.text());
      myEveryAttributes.push(tree.getAttribute);
    // you get the contents by using .text() insted of .name()
        if(tree.elements().length() > 0) {
            for(var i=0; i<tree.elements().length(); i++) {
                traverse(tree.elements()[i]);
    //============== End =====================//
    and the XML Structure is
    //===============XML =====================//
    <?xml version="1.0" encoding="UTF-8"?>< Entity_Convertion>
    < Entitys char="Ç" GID="173"/></ 
    Entity_Convertion>
    //===============End ====================//
    Here I'm getting the XML Elements and its contents, but not xmlAttributes.
    Please any one can help me, then I will appreciate...
    Thanks & Regards
    T.R.Harihara SudhaN

  • Imported XSLT cannot create attributes for generated XML element

    I have two xslts. One imports the other.
    The imported xslt creates XML elements with attributes and this XML is stored in a variable in the main stylesheet
    If I perform the transformation with JRE prior to 1.6.0.18 then all works fine
    If I use 1.6.0.18 or 1.6.0.19 then the attributes aren't added.
    If I add attributes in the main xslt it works fine or if I output the element directly instead of first storing it in a variable then it also works fine.
    Problem seems to be when you try to add attributes from an imported stylesheet and store the generated element in a variable.
    Below two stylesheets to illustrate :
    First MainStylesheet.xsl
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Copyright 1993-2005 Seagull Software Systems, Inc. -->
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:exsl="http://exslt.org/common"
    extension-element-prefixes="exsl"
    exclude-result-prefixes="xs">
    <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" />
    <xsl:import href="innerstylesheet.xsl"/>
    <xsl:template match="/TestData">
    <xsl:variable name="generatedElementXml">
    <xsl:call-template name="generateElement">
    <xsl:with-param name="s">testValue</xsl:with-param>
    </xsl:call-template>
    </xsl:variable>
    <xsl:for-each select="exsl:node-set($generatedElementXml)">
    *** GeneratedElementXML {<xsl:text>
    </xsl:text><xsl:copy-of select="*"></xsl:copy-of>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>Next innerstylesheet.xsl
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:exsl="http://exslt.org/common"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    extension-element-prefixes="exsl" >
            <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
            <xsl:template name="generateElement">
                       <xsl:param name="s"/>
                    <TestElement testAttribute="$s" />
            </xsl:template>
    </xsl:stylesheet>The result output by jres before 1.6.0.18 is :
    <?xml version="1.0" encoding="UTF-8"?>
                   *** GeneratedElementXML {
              <TestElement xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" testAttribute="testValue"/>
                   }          The result output by jres since 1.6.0.18 is :
    <?xml version="1.0" encoding="UTF-8"?>
                   *** GeneratedElementXML {
              <TestElement xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                   }          Note : the 'testAttribute' attribute is missing

    Have found the difference in the code
    In both JRE1.6.0_17 & JRE1.6.0_18, the class 'com.sun.org.apache.xalan.internal.xsltc.dom.AdaptiveResultTreeImpl' has the following method
    public void addUniqueAttribute(String qName, String value, int flags)
            throws SAXException
            addAttribute(qName, value);
        }In JRE1.6.0_17 the next method is
    public void addAttribute(String name, String value)
         if (_openElementName != null) {
             _attributes.add(name, value);
         else {
             BasisLibrary.runTimeError(BasisLibrary.STRAY_ATTRIBUTE_ERR, name);
        }In JRE1.6.0_18 the next method is
    public void addAttribute(String uri, String localName, String qname,
                String type, String value)
         if (_openElementName != null) {
             _attributes.addAttribute(uri, localName, qname, type, value);
         else {
             BasisLibrary.runTimeError(BasisLibrary.STRAY_ATTRIBUTE_ERR, qname);
        }Note - the addAttribute method has additional parameters in JRE1.6.0_18 but the call from addUniqueAttribute wasn't updated.
    So in JRE1.6.0_18 addUniqueAttribute actually invokes the following method in the base package com.sun.org.apache.xml.internal.serializer.EmptySerializer
    public void addAttribute(String name, String value)
            aMethodIsCalled();
    void aMethodIsCalled()
            // throw new RuntimeException(err);
            return;
        }and as you can see this does nothing. Hence the fact that the attribute isn't added.

  • How can I get the Attribute Value in the existing XML Elements-Reg.

    Dear All,<br /><br />  I have the InDesign Document with xml Based, now I want to get the XML Elements name and XML Attributes for each Elements, using SDK Concepts. <br /><br />Example:<br /><br /> <chapter>  chapter1 </chapter> id = "ch001"<br /> <sec> Section ....</sec> id ="se001"<br /> <para> para ....</para> id="pa001"<br /><br />How can I get the XMLElements & XML Attributes in the InDesign-XML Structure.<br /><br />Please  any one can suggest me....<br /><br />Thanks & Regards<br />T.R.Harihara SudhaN

    Dear Dirk
    Many Thanks for the Suggestions, Now I search and study the XML concepts. Meanwhile, I need your suggestions for further Development in SDK -XML concepts.
    I am using the SnippetRunner -SDK file, their given some XML based programmes. [Create XML Elements, Elements + Attributes, XML Comments] and etc...
    Hope U will help me to Develop the SDK- XML Concepts.
    Thanks & Regards
    T.R.Harihara SuduhaN

  • XML element,if not including any attributes and/or child elements then

    XML element in SQLX,if not including any attributes and/or child elements then the tag should not appear, how to achive this?
    ex:Consider for <enumeration> tag where it is having some value.
    <attribute>
    <name>Ethernet Access</name>
    <enumeration>
    <StringValue>Bandwidth</StringValue>
    </enumeration>
    </attribute>
    When <enumeration> tag is not have any Value in this, then output should be as follows.
    <attribute>
    <name>Ethernet Access</name>
    </attribute>
    But what i am getting is
    <attribute>
    <name>Ethernet Access</name>
    </enumeration>
    </attribute>
    Please suggest me the solution for this.
    I tried , but when xmlelement() is not having data it will display empty tag ie </enumeration>, If xmlforest() are null it wont show tag, But i have to use xmlelement only. how can that be achived using xmlelement .

    Use a SQL case - when - else end construct to only execute the xmlelement if data is present. The SQL/XML standard is very clear, xmlElement will generate an empty element if no data is present. xmlforest will not.

  • OC4J orion-application.xml - elements and attributes

    Hi. i read in oracle docs sentense like this: "Each property maps to an element attribute in the orion-application.xml descriptor." These properties are from deployment plan and i need to know what is the name of the element in orion-application.xml wich is mapped to webSiteBinding property (from deployment plan).

    I just did a quick test of this, and it seems to work for me.
    I used the following XML:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <Employees xmlns="
    http://www.foo.com/Employees">
    <Employee Id="001">
    <LastName>Davis</LastName>
    <FirstName>Kirk</FirstName>
    </Employee>
    <Employee Id="002">
    <LastName></LastName>
    <FirstName>James</FirstName>
    </Employee>
    <Employee Id="003">
    <FirstName>Anthony</FirstName>
    </Employee>
    <Employee>
    </Employee>
    </Employees>
    With the XPath "/Employees/Employee" I got rows in the data
    set and things displayed fine in my page. Changing it to
    "/employees/employee" caused the data set to have no rows which I
    would expect since things should be case sensitive.
    Can you provide me with some sample XML and XPath that
    doesn't work?
    Thanks!
    --== Kin ==--

  • Extracting the Attributes values of an XML Element

    Dear Forum Members
    Please tell me any XML Function which is used to extract the Attribute value of an XML Element.
    Given below
    <BRKCD_STREDSWTINVIN_C Key="6708">
    is an Element With some Key value.
    I want to have that Key value.
    Using Extract and Extractvalue I am not able to get the Attribute value.
    Is there any way..
    Regards
    Madhu K

    Your xml is not really complete ;), but this should get you started:
    michaels>  with t as
    (select xmltype('<BRKCD_STREDSWTINVIN_C Key="6708"></BRKCD_STREDSWTINVIN_C>') xml from dual)
    select d.xml, d.xml.extract('//BRKCD_STREDSWTINVIN_C/@Key') key
      from t d
    XML                                                            KEY    
    <BRKCD_STREDSWTINVIN_C Key="6708"></BRKCD_STREDSWTINVIN_C>     6708   

Maybe you are looking for