Read XML attributes

I have this xml.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
     <file name="Bohy" type="folder">
          <file name=".dropbox" type="file" />
          <file name="Beck" type="folder">
               <file name="desktop.ini" type="file" />
          </file>
     </file>
     <file name="Links.txt" type="file" />
     <file name="Pipo" type="folder">
     </file>
</root>And I need read attributes name and type, but with my code is not works. Can you repair me. Thanks
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
* @author thomas lokol
public class Main {
     private static DocumentBuilderFactory dbf;
     private static DocumentBuilder builder;
     private static Document doc;
      * @param args
     public static void main(String[] args) {
          createDocuments();
          // Root element
          Node node = doc.getDocumentElement();
          String rootElement = node.getNodeName();
          System.out.println("Root element: " + rootElement);
          readNodes(node.getChildNodes());
     private static void readNodes(NodeList nodeList) {
          System.out.println(nodeList.getLength());
          for (int i = 0; i < nodeList.getLength(); i++) {
               Node node = nodeList.item(i);
               if (node.getNodeType() == Node.ELEMENT_NODE) {
                    Element element = (Element)node;
               if(node.getNodeType() == Node.TEXT_NODE) {
                     NamedNodeMap attributes = node.getAttributes();
                     // Here is problem ...
                     for (int a = 0; a < attributes.getLength(); a++) {
                       Node theAttribute = attributes.item(a);
                       System.out.println(theAttribute.getNodeName() + "=" + theAttribute.getNodeValue());
     private static void createDocuments() {
          try {
               dbf = DocumentBuilderFactory.newInstance();
               builder = dbf.newDocumentBuilder();
               doc = builder.parse("myFile.xml");
          } catch (Exception e) {
               System.out.println("Chyba pri vytvareni");
               e.printStackTrace();
}Edited by: EJP on 23/04/2012 11:43: added {noformat}{noformat} tags. Please use them. Also fixed your title.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Hi,
I would suggest that you use a more simple library like Dom4j,
It is quite easy to use and is proven to have good performance on heavy tasks.
you can access xml attributes with a single line cod :
String value = element.attributeValue("Attribute name");you can download and view samples here : http://dom4j.sourceforge.net/

Similar Messages

  • Sample java code which reads xml attributes using DOM Parser

    Hi Friends,
    I am looking for a sample java code which uses the DOM Parser to read the attributes values.
    My xml looks like below
    <?xml version='1.0' encoding='UTF-8'?>
    <root>
    <header unid="100" status="true">
    <validation stage="1" processed="10"/>
    </header>
    </root>
    Experts please help...
    Thanks in Advance
    JJ

    You have probably found lots of resources on the www for this by now, if not: [http://www.w3schools.com/dom/default.asp|http://www.w3schools.com/dom/default.asp]

  • Help needed reading xml attributes

    I have a method that is reading through my XML doc and pulling out all of the elements. I want to get it to pull out the href attribute from within AdvertText but can't figure out how to do it within my method. Any help would be greatly appreciated!
    Here is the sample of the xml:
    <Advert groupName="Advert" type="group">
    <AdvertText dataType="RawString" fieldName="AdvertText" href="http://boston.craigslist.org/nos/abo/583827823.html" originalElement="a" type="field">First Floor Central Gloucester -</AdvertText>
    <Cost dataType="RawString" fieldName="Cost" href="http://boston.craigslist.org/nos/abo/583827823.html" originalElement="a" type="field">1350</Cost>
    <NumberOfBedrooms dataType="RawString" fieldName="NumberOfBedrooms" href="http://boston.craigslist.org/nos/abo/583827823.html" originalElement="a" type="field">3</NumberOfBedrooms>
    <Location dataType="RawString" fieldName="Location" originalElement="span" type="field">Gloucester</Location>
    </Advert>
    Here is my method:
    public Vector Read() {
            try {
                DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                Document doc = docBuilder.parse("http://www.dapper.net/RunDapp?dappName=CraigslistRentInfo&v=1&applyToUrl=http%3A%2F%2Fboston.craigslist.org%2Faap?query=&minAsk=min&maxAsk=max&bedrooms=1");
                // normalize text representation
                doc.getDocumentElement ().normalize ();
                System.out.println ("Root element of the doc is " +
                     doc.getDocumentElement().getNodeName());
                NodeList listOfAdverts = doc.getElementsByTagName("Advert");
                int totalAdverts = listOfAdverts.getLength();
                System.out.println("Total no of people : " + totalAdverts);
                RentAdvert myAd;
                String text;
                String loc;
                String bed;
                String cost;
                int y=10;
                for(int i=0; i<y ; i++){
                    Node firstAdvertNode = listOfAdverts.item(i);
                    if(firstAdvertNode.getNodeType() == Node.ELEMENT_NODE){
                        Element firstAdvertElement = (Element)firstAdvertNode;
                        NodeList advertTextList = firstAdvertElement.getElementsByTagName("AdvertText");
                        if((Element)advertTextList.item(0)==null){
                            text = "not available";
                        }else{
                        Element advertTextElement = (Element)advertTextList.item(0);
                        NodeList textATList = advertTextElement.getChildNodes();
                        System.out.println("Advert Text : " + ((Node)textATList.item(0)).getNodeValue().trim());
                        text = ((Node)textATList.item(0)).getNodeValue().trim();
                        //myAd.setAdvertText(text);
                        NodeList costList = firstAdvertElement.getElementsByTagName("Cost");
                        if((Element)costList.item(0)==null){
                            cost = "not available";
                        }else{
                        Element costElement = (Element)costList.item(0);
                        NodeList textCList = costElement.getChildNodes();
                        System.out.println("Cost : " + ((Node)textCList.item(0)).getNodeValue().trim());
                        cost = ((Node)textCList.item(0)).getNodeValue().trim();
                        //myAd.setCost(cost);
                        NodeList numberOfBedroomsList = firstAdvertElement.getElementsByTagName("NumberOfBedrooms");
                        if((Element)numberOfBedroomsList.item(0)==null){
                            bed = "not available";
                        }else{
                        Element numberOfBedroomsElement = (Element)numberOfBedroomsList.item(0);
                        NodeList textNOBList = numberOfBedroomsElement.getChildNodes();
                        System.out.println("Number of Bedrooms : " + ((Node)textNOBList.item(0)).getNodeValue().trim());
                        bed = ((Node)textNOBList.item(0)).getNodeValue().trim();
                        //myAd.setNumberOfBedrooms(bed);
                        NodeList locationList = firstAdvertElement.getElementsByTagName("Location");
                        if((Element)locationList.item(0)==null){
                            loc = "not available";
                        }else{
                        Element locationElement = (Element)locationList.item(0);
                        NodeList textLList = locationElement.getChildNodes();
                        System.out.println("Location : " + ((Node)textLList.item(0)).getNodeValue().trim());
                        loc = ((Node)textLList.item(0)).getNodeValue().trim();
                        //myAd.setLocation(loc);
                        if((text!="not available")&&(cost!="not available")&&(bed!="not available")&&(loc!="not available")){
                        myAd = new RentAdvert(text,cost,bed,loc);
                        listings.add(i,myAd);
                        }else{
                            y++;                       
                    }//end of if clause           
                }//end of for loop with s var
            }catch (SAXParseException err) {
            System.out.println ("** Parsing error" + ", line "
                 + err.getLineNumber () + ", uri " + err.getSystemId ());
            System.out.println(" " + err.getMessage ());
            }catch (SAXException e) {
            Exception x = e.getException ();
            ((x == null) ? e : x).printStackTrace ();
            }catch (Throwable t) {
            t.printStackTrace ();
            return listings;
        }//end of Read

    Works!
    NamedNodeMap a;
    a = n.getAttributes();
                    if(a != null) {
                    System.out.println("AttributesList: " + a);
                    System.out.println("NodeValue: " + a.item(0).getNodeValue());

  • Read XML attributes from RSS internet link

    I am very new to LabVIEW, and I am trying to determine the best way to read information an RSS link. Specfically, I would like to read data from a Yahoo! Weather RSS like http://weather.yahooapis.com/forecastrss?w=2502265. I would like to extract the temperature from <yweather: condition temp="[##]>, the wind speed from <yweather:wind speed="[##]">, and the text description from <yweather:condition text="[text]".
    I have looked into some XML parsing solutions like EasyXML, but I wonder if they are too much for what may be a simple task. I would appreciate any input on my current problem. Thanks.

    Howdy,
    It looks like EasyXML would make you life a little easier. You can search the LabVIEW Example Finder (Help menu->Find Examples) for XML examples. Other than that you would have to navigate to the website and parse the website source and use the LabVIW String Functions.
    Joshua B.
    National Instruments
    NI Services
    NI Support Resources
    NI Training Resources

  • How to display xml attributes in Layout (indesign cs2)

    Hi,
    Javascript
    Indesign CS2
    PC Version
    Any one tell me, i want to display the ids in the margin. i read xml attribute, but i didn't know how to display to the margin. Help me.

    One way of doing that is to use JDOM...
    u create an xml tree, and then output using XMLOutputter class...it will be displayed in text...im not sure if thats what u want...however, if u do want to represent it visually then u may need to draw a tree...u may use the Graphics2D for that...there are alot of ways to do such thing, and the 2 possibilities arent the best...depends on what u want...elaborate more pls.

  • Read XML (stored in Long Variable) through PL SQL

    Hi,
    We are on 11g2 Database. We have xml content in Long column/variable.
    Can anyone help me out to read xml attribute value ?
    eg.
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!DOCTYPE labels SYSTEM "label.dtd">
    <labels QUANTITY="1" JOBNAME="LBL213685">
    <label FORMAT="XEINSP_REQ_LBL.lwl">
    <variable name= "L_DATE">04-JAN-2012</variable>
    <variable name= "L_TIME">10:45:17</variable>
    <variable name= "L_LPN">K01-4713BE</variable>
    <variable name= "L_ITEM">XXXXWT88-002</variable>
    <variable name= "L_ITEMDESC">SPRING,REVERSIBLE EXPANSION GE14 234C6745P001 REV.01</variable>
    <variable name= "L_QTY">1</variable>
    <variable name= "L_POREV"></variable>
    <variable name= "L_PONUM">837037254</variable>
    <variable name= "L_ITEMREF">834C6745P001</variable>
    <variable name= "L_PROJECT"></variable>
    <variable name= "L_ISIS"></variable>
    <variable name= "L_LABEL">1</variable>
    <variable name= "L_LINE_NO">1</variable>
    <variable name= "L_SUPPLIER">RECISION OIL, INC</variable>
    </label>
    </labels>
    We want to read value next to <variable name= "L_LPN"> . Need to return K01-4713BE programmatically.
    Appreciate your help.
    Thanks,
    Abhi
    Edited by: user649769 on Jan 4, 2012 2:52 PM
    Edited by: user649769 on Jan 4, 2012 2:53 PM

    Hi,
    As you may be aware, LONG datatype is obsolete for quite some time now.
    If you can you should really consider migrating it to CLOB, or in this specific case store XML data in an XMLType column.
    In particular, we can't use XMLType constructor directly on a LONG.
    Here's a simple PL/SQL solution though, provided the data is not larger than 32k :
    SQL> create table test_long (xmldoc long);
    Table created
    SQL> insert into test_long values('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
      2  <!DOCTYPE labels SYSTEM "label.dtd">
      3  <labels _QUANTITY="1" _JOBNAME="LBL213685">
      4  <label _FORMAT="XE_INSP_REQ_LBL.lwl">
      5  <variable name= "L_DATE">04-JAN-2012</variable>
      6  <variable name= "L_TIME">10:45:17</variable>
      7  <variable name= "L_LPN">K01-4713BE</variable>
      8  <variable name= "L_ITEM">XXXXWT88-002</variable>
      9  <variable name= "L_ITEMDESC">SPRING,REVERSIBLE EXPANSION GE14 234C6745P001 REV.01</variable>
    10  <variable name= "L_QTY">1</variable>
    11  <variable name= "L_POREV"></variable>
    12  <variable name= "L_PONUM">837037254</variable>
    13  <variable name= "L_ITEMREF">834C6745P001</variable>
    14  <variable name= "L_PROJECT"></variable>
    15  <variable name= "L_ISIS"></variable>
    16  <variable name= "L_LABEL">1</variable>
    17  <variable name= "L_LINE_NO">1</variable>
    18  <variable name= "L_SUPPLIER">RECISION OIL, INC</variable>
    19  </label>
    20  </labels>');
    1 row inserted
    SQL> commit;
    Commit complete
    SQL> set serveroutput on
    SQL> DECLARE
      2 
      3    v_xmldoc   varchar2(32767);
      4    v_result   varchar2(30);
      5 
      6  BEGIN
      7 
      8    select xmldoc into v_xmldoc from test_long;
      9 
    10    /* disable DTD validation for the current session */
    11    execute immediate 'alter session set events = ''31156 trace name context forever, level 2''';
    12 
    13    select xmlcast(
    14             xmlquery('/labels/label/variable[@name="L_LPN"]'
    15                      passing xmltype(v_xmldoc)
    16                      returning content)
    17             as varchar2(30)
    18           )
    19    into v_result
    20    from dual
    21    ;
    22 
    23    execute immediate 'alter session set events = ''31156 trace name context off''';
    24 
    25    dbms_output.put_line(v_result);
    26 
    27  END;
    28  /
    K01-4713BE
    PL/SQL procedure successfully completed
    Note that I used event 31156 to temporarily disable DTD validation on the XML document, and avoid this :
    ORA-31001: Invalid resource handle or path name "/label.dtd"If you want to actually use validation, the DTD has to be stored in the XML DB repository (in the root folder).

  • How to read an attribute of an xml tag in jsp.

    hi guys,
    This is murali krishna. i have a small problem,
    i have one xml file (books.xml)
    <?xml version="1.0" encoding="iso-8859-1"?>
    <library>
    <book id="1">
    <name>Head First Java, 2nd Edition</name>
    <author>Kathy Sierra and Bert Bates</author>
    <publication-date>09-Feb-2005</publication-date>
    </book>
    <book id="2">
    <name>Effective Java</name>
    <author>Joshua Bloch</author>
    <publication-date>28-May-2008</publication-date>
    </book>
    <book id="3">
    <name>Java How to Program, 7th Edition</name>
    <author>Harvey M. Deitel and Paul J. Deitel</author>
    <publication-date>6-Jan-2007</publication-date>
    </book>
    </library>
    I tried to read this xml file in jsp as shown below
    <%@ page language="java" %>
    <%@ page import="org.w3c.dom.*" %>
    <%@ page import="javax.xml.parsers.DocumentBuilder" %>
    <%@ page import="javax.xml.parsers.DocumentBuilderFactory" %>
    <%
    DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
    DocumentBuilder db =dbf.newDocumentBuilder();
    Document doc=db.parse("c:\\books.xml");
    NodeList nl = doc.getElementsByTagName("book");
    %>
    <html>
    <head>
    <title>How to read XML file in JAVA</title>
    </head>
    <body>
    <%
    for(int i=0;i<nl.getLength();i++)
    NodeList nameNlc= doc.getElementsByTagName("name");
    Element nameElements=(Element)nameNlc.item(i);
    String nameTagValue=nameElements.getChildNodes().item(0).getNodeValue();
    NodeList authorNlc= doc.getElementsByTagName("author");
    Element authorElements=(Element)authorNlc.item(i);
    String authorTagValue=authorElements.getChildNodes().item(0).getNodeValue();
    NodeList dateNlc= doc.getElementsByTagName("publication-date");
    Element dateElements=(Element)dateNlc.item(i);
    String dateTagValue=dateElements.getChildNodes().item(0).getNodeValue();
    out.println("name :"+nameTagValue+"<br>");
    out.println("author :"+authorTagValue+"<br>");
    out.println("publication-date :"+dateTagValue+"<br><br>");
    %>
    </body>
    </html>
    so, my problem is I was unable to read the attribute of the tag book , that is "id".
    can any one tell me how to read this "id" attribute.
    Murali Krishna
    [email protected]

    hi,
    U r retriving the elements by tag name.So it just chks the tag name ie.<book> & gives u array of elements.But u need retrive d attribute of <book> tag itself.
    =Solution =====
    Add one more statement ----> var[]= doc.getElementsByName("book");
    Now u hav book elements as an array & can retrive id in for loop
    for(var; var.length;var++)
    doc.element[var].id.value

  • How to read the attribute of the xml file using jaxb

    Thanks,
    Buddy as i have a issue i have to read the xml file using jaxb and xml file contains this data and i have read the attribute like name , desc and action for a particular menu name pls tell the code how to do this it will be a great favour to me
    thanx in advance
    Rasool
    <contextmenu>
    <menu name='Lead' >
    <menuitem name='newlead' desc='New Lead' action='/leads.do?dispatch=insert' />
    <menuitem name='editlead' desc='Edit Lead' action='' />
    <menuitem name='leadinfo' desc='Lead Information' action='' />
    </menu>
    <menu name='Cases' >
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    </menu>
    <menu name='Contact' >
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    <menuitem name='' desc='' action='' />
    </menu>
    </contextmenu>

    What my program do is to get the encoding of XML files and convert them to UTF-8 encoding files, while I need this "encoding" information of the original XML document thus I can convert...
    After reading specifications and JDOM docs, the truth turns to be disappointed, no function is provided to get this information in JDOM level 2(the current released one), while it's promissed that this function will be provided in JDOM level API....
    Thanx all for your help and attention!!!

  • How to read the attribute in mapping..

    Hi,
    My source XML looks like this
    <GLDEBITACCT>
                <VALUE>0545-K-2006605-5500001</VALUE>
                <GLCOMP glorder="0">0545</GLCOMP>
                <GLCOMP glorder="1">K</GLCOMP>
                <GLCOMP glorder="2">2006605</GLCOMP>
                <GLCOMP glorder="3">5500001</GLCOMP>
      </GLDEBITACCT>
    Where glorder is the attribute of GLCOMP. Now I have requirement to read the attribute ( atleast 2 of them)
    I have to map to target field checking the value in glorder="1
    For e.g. with above XML, if the value in glorder="1 is K than map value from glorder="2 (2006605) to Target 1.
    IF the glorder="1 is P map the value in glorder="2 to Target 2 and goes on for another one
    How can i acheive this mapping. When I tried putting the value of glorder, i am not getting anything.
    Regards,

    Hi,
    You can use below UDF. Please make sure to select context parameter while creating UDF. There will be 3 input arguments for this function:
    1. GLCOMP (a)
    2 @glorder   (b)
    3 Constant   (c)  --depending upon the target node
    Also conext of attribute @glorder should be same as that of GLCOMP.
    //write your code here
    for(int i=0;i<a.length;i++)
        if(b<i>.equals("1")&&c[0].equals(a<i>))
        for(int j=0;j<a.length;j++)
              if(b[j].equals("2"))
         result.addValue(a[j].toString());
                            break;
    For target node target1 use K as 3rd argument, for target node target2 use P and so on.
    Let me know how it works.
    Regards,
    Anirudh.

  • Getting at a top-level XML attribute

    It's Friday afternoon... I'm fried and can't seem to figure
    out how to get at a top-level XML attribute.
    Some specifics...
    My XML doc has a single attribute in the top node followed by
    several "version" nodes
    <projData projectName="Spry Project">
    <version>
    I successfully load and create an xml data set from said XML
    file. Later on, I use the getDocument() method to refer to the XML
    DOM doc used by the original xml data set. I need to extract the
    value of the attribute "projectName" into a javascript variable.
    The xpath query should be "projData/@projectName" but all I
    get returned is an undefined value.
    Any ideas? I'm sure it's something simple that I'm
    overlooking.

    > can you please helo.
    This is impossible.
    Obviously your ABAP mapping is wrong. Fix it.

  • How to read XML data stored in CLOB in Concurrent prog Output

    Hi All,
    I'm trying to Generate the XML Data as concurrent Program output. I have a PL/SQL package which generated the XML data by using SQL/XML functions. I'm storing the generated XML data in a CLOB variable. But when i try to read the data using fnd_file.put_line(fnd_file.OUTPUT,XML_Data) it doesn't display data more than 32767 bytes.
    Please help me out to understand what could be done to read the data in chunks. I have tried many logic's to print chunks of data but the output tags are either chopped off and errors out saying Tag not found.
    My logic is as below:
    v_handler:= DBMS_XMLGEN.newContext(v_xml_query);
    --Sets NULL handling options
    DBMS_XMLGen.SetNullHandling(v_handler, dbms_xmlgen.EMPTY_TAG ) ;
    --Set special character handling
    DBMS_XMLGEN.setConvertSpecialChars(v_handler, TRUE);
    -- Specified whether to use an XML attribute to indicate NULLness of particular entity in the XML document
    DBMS_XMLGen.useNullAttributeIndicator(v_handler,TRUE);
    -- set Checking invalid chars
    DBMS_XMLGEN.setCheckInvalidChars(v_handler, TRUE);
    -- get the xml data as required
    v_xml_data:= DBMS_XMLGEN.getXMLtype(v_handler);
    SELECT XMLROOT(v_xml_data.extract('/*'),VERSION '1.0').getClobVal() into v_new_xml_Data from dual;
    -- get the length of the xml generated
    v_clob_len := dbms_lob.getlength(v_new_xml_Data);
    FND_FILE.PUT_LINE(FND_FILE.LOG,'The Clob length is :'|| v_clob_len);
    -- logic to process string more than 32767 Processing by each character
    v_offset :=1;
    while (v_offset <= v_clob_len)
    LOOP
    v_char := dbms_lob.substr(v_new_xml_Data, 1, v_offset);
    IF (v_char = CHR(10))
    then
    fnd_file.new_line(fnd_file.output, 1);
    else
    fnd_file.put(fnd_file.output, v_char);
    end if;
    v_offset := v_offset + 1;
    END LOOP;
    FND_FILE.PUT_LINE(FND_FILE.LOG,'The offset is :'|| v_offset);
    FND_FILE.NEW_LINE(FND_FILE.OUTPUT, 1);
    THe above logic is for character by character which is a performance burden? Please let me know if there is any other work around for this

    Hi,
    Thanks for Replying. I have refered http://blog.oraclecontractors.com/?p=69 and then i added that piece of code. Basically, i'm trying to generate a report using XML publisher. To generate the XML data i'm writing a pl/sql package with SQl/XML functions. DBMS_XMLGEN would help me convert the XML Data as is. When the concurrent program runs this XML data will merge with RTF layout and generate required report. I'm able to generate the Report for data less then 32767 bytes. More than the limit i need to pass chunks of XML data to read as output. That's the reason i'm using fnd_file.output. But it reads only 32767 size at a time.
    WHen i use the given logic, it works perfectly fine, but it loops for each character, for example if you have 30,000 characters it loops the same, which is peformance burden.
    So i tried to write the logic of chunks but still i get the error that XML tag is not found or missing. I'm hoping this is very common issue, but after all my trails, i didn't find the right solution.
    the other logic i tried was :
    v_new_xml_data varchar2(32767)
    v_iterations := CEIL(v_clob_len/v_chunk_length); -- v_chunk_length is 32767 and v_clob_length is length of the XML data stored inthe clob variable
    For i in 0..v_iterations
    LOOP
    FND_FILE.put_line (fnd_file.log,'the loops v_pos :'||i||' and v_clob_length :'||v_clob_len);
    v_new_xml_data := DBMS_LOB.SUBSTR ( V_XML_DATA,v_chunk_length,(i*v_chunk_length)+1);
    FND_FILE.PUT_LINE (FND_FILE.OUTPUT,v_new_xml_data); -- read the output for every 32767 chunks
    FND_FILE.PUT_LINE(FND_FILE.LOG, 'Chunk length is :'||((i*v_chunk_length)+1));
    END LOOP;
    FND_FILE.put_line (fnd_file.log,'out of loop');
    FND_FILE.put_line (fnd_file.log,'length of new xml is '||v_clob_len);
    Please, let me know if you need Further clarifications on the same.

  • Read XML file from presentation server

    Hi All,
    I want read XML file from presentation server currently i am using GUI_UPLOAD fm . but it is reading some junk data.
    DATA : BEGIN OF upl OCCURS 0,
              f(255) TYPE c,
           END OF upl.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename = D:\XX.XML'
          filetype = 'BIN'
        TABLES
          data_tab = upl.
    is there any other alternative.
    Thanks
    Swarup,

    Hi Swarup,
    Use method IMPORT_FROM_FILE of class CL_XML_DOCUMENT.
    A sample code snippet :-
    PARAMETERS: p_filnam TYPE localfile OBLIGATORY
    DEFAULT 'C:\Documents and Settings\ssaha\Desktop\test.xml'.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_filnam.
    DATA: l_v_fieldname TYPE dynfnam.
    l_v_fieldname = p_filnam.
    CALL FUNCTION 'F4_FILENAME'
    EXPORTING
    program_name = syst-cprog
    dynpro_number = syst-dynnr
    field_name = l_v_fieldname
    IMPORTING
    file_name = p_filnam.
    START-OF-SELECTION.
    TYPES:
    BEGIN OF ty_tab,
    name TYPE string,
    value TYPE string,
    END OF ty_tab.
    DATA:
    lcl_xml_doc TYPE REF TO cl_xml_document,
    v_subrc TYPE sysubrc,
    v_node TYPE REF TO if_ixml_node,
    v_child_node TYPE REF TO if_ixml_node,
    v_root TYPE REF TO if_ixml_node,
    v_iterator TYPE REF TO if_ixml_node_iterator,
    v_nodemap TYPE REF TO if_ixml_named_node_map,
    v_count TYPE i,
    v_index TYPE i,
    v_attr TYPE REF TO if_ixml_node,
    v_name TYPE string,
    v_prefix TYPE string,
    v_value TYPE string,
    v_char TYPE char2.
    DATA:
    itab TYPE STANDARD TABLE OF ty_tab,
    wa TYPE ty_tab.
    CREATE OBJECT lcl_xml_doc.
    CALL METHOD lcl_xml_doc->import_from_file
    EXPORTING
    filename = p_filnam
    RECEIVING
    retcode = v_subrc.
    CHECK v_subrc = 0.
    v_node = lcl_xml_doc->m_document.
    CHECK NOT v_node IS INITIAL.
    v_iterator = v_node->create_iterator( ).
    v_node = v_iterator->get_next( ).
    WHILE NOT v_node IS INITIAL.
    CASE v_node->get_type( ).
    WHEN if_ixml_node=>co_node_element.
    v_name = v_node->get_name( ).
    v_nodemap = v_node->get_attributes( ).
    IF NOT v_nodemap IS INITIAL
    * attributes
    v_count = v_nodemap->get_length( ).
    DO v_count TIMES.
    v_index = sy-index - 1.
    v_attr = v_nodemap->get_item( v_index ).
    v_name = v_attr->get_name( ).
    v_prefix = v_attr->get_namespace_prefix( ).
    v_value = v_attr->get_value( ).
    ENDDO.
    ENDIF.
    WHEN if_ixml_node=>co_node_text OR
    if_ixml_node=>co_node_cdata_section.
    * text node
    v_value = v_node->get_value( ).
    MOVE v_value TO v_char.
    IF v_char <> cl_abap_char_utilities=>cr_lf.
    wa-name = v_name.
    wa-value = v_value.
    APPEND wa TO itab.
    CLEAR wa.
    ENDIF.
    ENDCASE.
    * advance to next node
    v_node = v_iterator->get_next( ).
    ENDWHILE.
    LOOP AT itab INTO wa.
    ENDLOOP.
    Regards
    Abhii

  • Reading XML File from application server

    Hi experts,
    My aim is to read a XML file from application server and extract the relevant data from it and process further.
    When I am trying to read a XML file from application server it is reading success fully but the problem is that its not reading the last root structure of XML file why is so happening can any body help me?
    I am using the following code:
    TYPES: BEGIN OF xml_line,
    text(256) type x,
    END OF xml_line.
    DATA: e_file LIKE rlgrap-filename VALUE  'applcatin server path'
    OPEN DATASET e_file FOR INPUT IN BINARY MODE.
    IF sy-subrc EQ 0.
      DO.
        READ DATASET e_file INTO wa_item1-text.
        IF sy-subrc EQ 0.
          APPEND wa_item1 TO gt_item1 .
          CLEAR wa_item1.
        ELSE.
          EXIT.
        ENDIF.
      ENDDO.
    ENDIF.
    CLOSE DATASET e_file.
    after this i am passing this internal table to "cl_ixml" class to extract the data
    but it returning the itab with required value except the last record.
    The stream reading the file it self is i thought in complete thats why it is not converting the all values.
    Please  help me...
    Thanks a ton in advance.

    Hi,
    1 Copy Report BCCIIXMLT1
    2 (you can change the way of filling internal table xml_table if necessary)
    3 you don't need the part between
    *-- render the DOM back into an output stream/internal table
    and
    *-- print the whole DOM tree as a list...
    Comment it out or simply delete it
    4 Rename form print_node to your liking e.g. process_node
    5 In your new form you need three extra variables:
    data: attribs type ref to IF_IXML_NAMED_NODE_MAP,
          attrib_node type ref to IF_IXML_NODE,
          attrib_value type string.
    6 After the lines:
    when if_ixml_node=>co_node_element.
      string = pNode->get_name( ).
    Insert:
    attribs = pNode->get_attributes( ).
    clear attrib_value.
    case string.
      when ''. "put your XML tag name here
        attrib_node = attribs->get_named_item(name = '' ). "put your XML attribute name here
        attrib_value = attrib_node->get_value( ).
    You can also refer link,
    /people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach
    thanks & regards
    shreemohan

  • File-Adapter: Variable substitution form payload XML-attribute

    Hi experts,
    is possible to use XML-attribute-content for variable substitution in file-Adapter?
    extract from XML:
    <?xml version="1.0" encoding="utf-8" ?>
    - <all>
    - <transaction <b>file="filename"</b>>
    - <table name="BPAADDRESS" options="insertIfUpdateFails">
    - <record id="1">
      <hkeycol name="BPAMAINHKEY">0010500345</hkeycol>
      <hkeycol name="USAGE">Invoice</hkeycol>
      </transaction>
    I want to get the value "filename" = attribute file of transaction.
    Is this possible?
    Thanks a lot,
    Florian

    I have done this taking a field from the XML.
    You have to map the location of the field within the XML...
    Taken from:
    http://help.sap.com/saphelp_nw04/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/frameset.htm
    Variable Substitution (Target Directory/File Name Scheme)
    If you set the Enable indicator, you can enter variables for the Target Directory and File Name Scheme. Enter the names of the variables and references in the table.
    &#9679;      Enter each variable that you reference in the Target Directory and File Name Scheme fields without the surrounding percentage sign under Name of Variables in the table.
    The variables can refer to attributes of the message header or elements of the message payload.
    &#9675;       If the variables are to refer to an attribute of the message header, add the prefix message: to the name of the variable under Reference. You can specify the following attributes of the message header:
    sender_party, sender_service, receiver_party, receiver_service, interface_name, interface_namespace,
    message_id (message ID with hyphens, for example 9fbe1ff1-9a0d-11d9-8665-cbf10a126331)
    message_id_hex (message ID in hexadecimal format, for example 9fbe1ff19a0d11d98665cbf10a126331)
    For example, if you want to specify the interface name from the message header in the target directory or in the file name scheme, enter message:interface_name as the reference.
    If one of the message attributes contains characters that are not permitted in a file name, for example \, /, :, *, ?, ", <, >, |, then these characters are replaced by an underscore ("_").
    &#9675;       If the variable refers to an element in XML schema, add the prefix payload: to the information under Reference. The reference then comprises a pseudo path description in the form of a comma-separated list with the schema namea,na,nameb,nb,....
    namea,nameb,... corresponds to the element name and na,nb,... corresponds to the occurrence of the element name at the respective level in the document.
    The description begins at the root of the document and ends at the respective element.
    To reference the element that is in bold in the example, the following expression is used: payload:root,1,e1,1,e2,2
    The parser searches for the first occurrence of the root element at the first level. It then searches for the first occurrence of e1 at the second level and for the second occurrence of e2 at the third level. The content of the last element (“Example Value”) is set as the value for a specified variable.
    <?xml version="1.0" encoding="UTF-8" ?>
    <root>
      <dummy>
         <e1>
            <e2>Data_1</e2>
            <f/>
            <g attr="abc">text</g>
            <e2>Data_2</e2>
         </e1>
      </dummy>
      <e1>
         <e2>illegal/value</e2>
         <f/>
         <g attr="abc">text</g>
         <e2 attr="fghij">Example Value</e2>
      </e1>
    </root>
    &#9679;      To disable the check the adapter performs for the element data, set the Disable Security Checks indicator.
    Otherwise, the adapter checks whether the element data contains characters that could lead to security risks in the file system environment. The check includes the characters “/“, “\“, and “..“.

  • XML attributes as a response

    My skills are rudimentary, I'm a new flex developer. I have
    done all of the tutorials and examples and I'm just struggling with
    using an XML attribute checking a response.
    I've written a simple flex 3 app to talk to Asterisk AJAM.
    I'm writing the login piece-- and i'm having trouble parsing this
    response from an http service (successful login) my problem comes
    in with the value not being as such
    <item>valuehere</item> it's part of the tag, an
    attribute i would suppose.:
    <ajax-response>
    <response type="object" id="unknown">
    <generic response="Success" message="Authentication
    accepted"/>
    </response>
    </ajax-response>
    What I have is a simple app with a http service and a login
    form. I have an event handler for the HTTP service, but I don't
    know how to parse for that generic response tag. Anyone know how to
    format an XML object for that type of response and throw a simple
    if statement looking for that attribute?
    Failure looks like this BTW:
    <ajax-response>

    <response type="object" id="unknown">
    <generic response="Error" message="Authentication
    failed"/>
    </response>
    </ajax-response>
    Thank you,
    Brian

    I've came up with the following code trying to use XML
    attributes from the response above--- it doesn't work but here is
    what I have (right now the if statement is commented out.... i'm
    trying to have it do an alert which doesn't work either):
    ---source---
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:states>
    <mx:State name="Logged In">
    <mx:SetProperty target="{panel1}" name="width"
    value="95%"/>
    <mx:SetProperty target="{panel1}" name="height"
    value="95%"/>
    <mx:RemoveChild target="{password}"/>
    <mx:RemoveChild target="{username}"/>
    <mx:RemoveChild target="{label1}"/>
    <mx:RemoveChild target="{Submit}"/>
    <mx:RemoveChild target="{label2}"/>
    <mx:SetProperty target="{panel1}" name="title"
    value="Once Logged In"/>
    <mx:AddChild relativeTo="{panel1}"
    position="lastChild">
    <mx:Label x="10" y="10" text="You properly
    authentictaed!"/>
    </mx:AddChild>
    <mx:AddChild relativeTo="{panel1}"
    position="lastChild">
    <mx:Label x="10" y="62" text="Label"/>
    </mx:AddChild>
    </mx:State>
    </mx:states>
    <mx:Script>
    <![CDATA[
    import mx.rpc.events.ResultEvent;
    var MyXML:XML;
    private function checkLogin(evt:ResultEvent):void
    MyXML = evt.result.channel.item;
    mx.controls.Alert.show(MyXML.@*);
    trace(MyXML.@*.toXMLString());
    /* if (MyXML.attribute(ajax-response.response.@generic) ==
    "Success") {
    if (MyXML.ajax-response.response.(@generic == "Success"))
    currentState = "Logged In";
    if (MyXML.ajax-response.response.(@generic == "Error"))
    mx.controls.Alert.show('Invalid username/password');
    ]]>
    </mx:Script>
    <mx:HTTPService id="login_user"
    result="checkLogin(event)" showBusyCursor="true" method="GET" url="
    http://72.22.224.90:8088/asterisk/mxml"
    useProxy="false">
    <mx:request xmlns="">
    <action>login</action>
    <username>
    {username.text}
    </username>
    <password>
    {password.text}
    </password>
    </mx:request>
    </mx:HTTPService>
    <mx:Panel resizeEffect="Resize" width="250" height="200"
    layout="absolute" title="Login System" horizontalCenter="0"
    verticalCenter="-2" id="panel1">
    <mx:Label x="10" y="10" text="Username:" id="label1"/>
    <mx:TextInput x="10" y="36" id="username"/>
    <mx:Label x="10" y="66" text="Password:" id="label2"/>
    <mx:TextInput x="10" y="92" id="password"
    displayAsPassword="true"/>
    <mx:Button x="10" y="122" label="Submit" id="Submit"
    click="login_user.send();"/>
    </mx:Panel>
    </mx:Application>

Maybe you are looking for

  • Not able to change an existing document in cv02n

    Hi Freinds. Greetings. I am new in SAP DMS.I have created one document type ZTS and based on that i creted one test Document using Tcode CV01n, The internal No. range is assigned for this document type. Now i am trying to change this document using C

  • CS6 Web Gallery template selection problem, need help...

    Using Bridge CS6  to create a web gallery and the only template available is "Standard" which is Flash based. I can open the pull down menu and see 11 templates including the HTML which I want to use but it defaults back to "standard" each time. Seem

  • Adobe Flash not installing on OS X 10.8.5?

    Hi everyone, I have been trying to update Flash Player on my Macbook Air, but for some reason every time I open the .dmg and click on the installer the program freezes and I get the wheel of death. I did the usual check and uninstalled Flash complete

  • ERROR MESSAGE - "no applications are set up or enabled for synchronization blackberry"

    I own a BB Bold 9700 and have recently changed laptop using Windows 7 64 bit and Outlook 2010.  Since upgrading to the new desktop software I am unable to sync my BB. I have gone through the configuration settings, but no tick marks appear having con

  • Immature Java Programmer needs help...

    I do not want to generate html code inside my java code, rather open a html page by referencing it in my java code to see it in the browser. For example, here is my code: package mrpt; import java.io.*; import javax.servlet.*; import javax.servlet.ht