XML DOM Parsing getAttributes() in J2SE 5.0 vs. J2SE 1.4

I am experiencing the following problem, with the Node.getAttributes() function although the following code runs fine under Java 1.4, and getAttributes() returns the actual string attribute values:
            File xmlFile = new File(fileName);
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(xmlFile);
            // Begin analyzing XML
            Element root = doc.getDocumentElement();
            // Enumerate all children
            NodeList children = root.getChildNodes();
                Node rootNode = null;
                NodeList nodeList = children;
                for (int R = 0; R < nodeList.getLength() ; R++)
                    if (nodeList.item(R).getNodeType() == Node.ELEMENT_NODE)
                        rootNode = nodeList.item(R);
                        System.out.println("> " + rootNode.getNodeName() + " - " + rootNode.getAttributes().toString());
             In J2SE 5.0 the Node.getAttributes() returns the following:
[email protected]d of returning then the actual attribute string (like in Java 1.4)!
If it helps at all I am using DOM parser (as noticed above, org.w3c.dom)
My assumption is that J2SE 5.0 returns an attribute map that is encoded differently then Java 1.4
Thank you for your time & appreciate any help...

The getAttributes method returns a NamedNodeMap.
Iterate over the NamedNodeMap to get attribute values.
Instead of rootNode.getAttributes().toString();
NamedNodeMap map=rootNode.getAttributes().toString();
for(int i=0; i<map.getLength(); i++){
Node node=map.item(i);
if(node.getNodeType()==Node.ATTRIBUTE_NODE)
System.out.println("Attribute Node "+node.getNodeName()+ "has value "+ node.getNodeValue());
}

Similar Messages

  • Oracle XML DOM parser - attribute values are not printing on the screen ??

    Hi Everyone,
    I am just trying to use oracle DOM parser to paerse one of my xml file, java file can be compiled and run agianst a xml file, But I cannot see any attribute values printing on the screen..
    Appreciate if anyone can help, where I have gone wrong please?
    Below is the java file:
    // menna puthe DOMSample eka - duwanawa 19/12/2005
    import java.io.*;
    import java.net.*;
    import org.w3c.dom.*;
    import org.w3c.dom.Node;
    import oracle.xml.parser.v2.*;
    public class DOMSample {  //public class eka ***
    static public void main(String[] argv){  // main method eka ###
    try {
    if (argv.length != 1){
    // Must pass in the name of the XML file...
    System.err.println("Usage: java DOMSample filename");
    System.exit(1);
    // Get an instance of the parser
    DOMParser parser = new DOMParser();
    // Generate a URL from the filename.
    URL url = createURL(argv[0]);
    // Set various parser options: validation on,
    // warnings shown, error stream set to stderr.
    parser.setErrorStream(System.err);
    parser.showWarnings(true);
    // Parse the document.
    parser.parse(url);
    // Obtain the document.
    Document doc = parser.getDocument();
    // Print document elements
    System.out.print("The elements are: ");
    printElements(doc);
    // Print document element attributes
    System.out.println("The attributes of each element are: ");
    printElementAttributes(doc);
    catch (Exception e){
    System.out.println(e.toString());
    } // main method eka ###
    static void printElements(Document doc) {
    NodeList nl = doc.getElementsByTagName("*");
    Node n;
    for (int i=0; i<nl.getLength(); i++){
    n = nl.item(i);
    System.out.print(n.getNodeName() + " ");
    System.out.println();
    static void printElementAttributes(Document doc){
    NodeList nl = doc.getElementsByTagName("*");
    Element e;
    Node n;
    NamedNodeMap nnm;
    String attrname;
    String attrval;
    int i, len;
    len = nl.getLength();
    for (int j=0; j < len; j++){
    e = (Element)nl.item(j);
    System.out.println(e.getTagName() + ":");
    nnm = e.getAttributes();
    if (nnm != null){
    for (i=0; i<nnm.getLength(); i++){
    n = nnm.item(i);
    attrname = n.getNodeName();
    attrval = n.getNodeValue();
    System.out.print(" " + attrname + " = " + attrval);
    System.out.println();
    static URL createURL(String filename) {  // podi 3 Start
    URL url = null;
    try {
    url = new URL(filename);
    } catch (MalformedURLException ex) { /// BBBBBB
    try {
    File f = new File(filename);
    url = f.toURL();
    } catch (MalformedURLException e) {
    System.out.println("Cannot create URL for: " + filename);
    System.exit(0);
    } // BBBBBB
    return url;
    } // podi 3 End
    } //public class eka ***
    // End of program
    output comes as below:
    Isbn:
    Title:
    Price:
    Author:
    Message was edited by:
    chandanal

    Hi Chandanal,
    I edited your code slightly and I was able to get the correct output.
    I changed the following line:
    for (int j=0; j >< len; j++)to:
    for (int j=0; j < len; j++)I have included the complete source below:
    // menna puthe DOMSample eka - duwanawa 19/12/2005
    import java.io.*;
    import java.net.*;
    import org.w3c.dom.*;
    import org.w3c.dom.Node;
    import oracle.xml.parser.v2.*;
    public class DOMSample {
        //public class eka ***
        public static void main(String[] argv) {
            // main method eka ###
            try {
                if (argv.length != 1) {
                    // Must pass in the name of the XML file...
                    System.err.println("Usage: java DOMSample filename");
                    System.exit(1);
                // Get an instance of the parser
                DOMParser parser = new DOMParser();
                // Generate a URL from the filename.
                URL url = createURL(argv[0]);
                // Set various parser options: validation on,
                // warnings shown, error stream set to stderr.
                parser.setErrorStream(System.err);
                parser.showWarnings(true);
                // Parse the document.
                parser.parse(url);
                // Obtain the document.
                Document doc = parser.getDocument();
                // Print document elements
                System.out.print("The elements are: ");
                printElements(doc);
                // Print document element attributes
                System.out.println("The attributes of each element are: ");
                printElementAttributes(doc);
            } catch (Exception e) {
                System.out.println(e.toString());
        // main method eka ###
        static void printElements(Document doc) {
            NodeList nl = doc.getElementsByTagName("*");
            Node n;
            for (int i = 0; i < nl.getLength(); i++) {
                n = nl.item(i);
                System.out.print(n.getNodeName() + " ");
            System.out.println();
        static void printElementAttributes(Document doc) {
            NodeList nl = doc.getElementsByTagName("*");
            Element e;
            Node n;
            NamedNodeMap nnm;
            String attrname;
            String attrval;
            int i, len;
            len = nl.getLength();
            for (int j = 0; j < len; j++) {
                e = (Element)nl.item(j);
                System.out.println(e.getTagName() + ":");
                nnm = e.getAttributes();
                if (nnm != null) {
                    for (i = 0; i < nnm.getLength(); i++) {
                        n = nnm.item(i);
                        attrname = n.getNodeName();
                        attrval = n.getNodeValue();
                        System.out.print(" " + attrname + " = " + attrval);
                System.out.println();
        static URL createURL(String filename) {
            // podi 3 Start
            URL url = null;
            try {
                url = new URL(filename);
            } catch (MalformedURLException ex) {
                /// BBBBBB
                try {
                    File f = new File(filename);
                    url = f.toURL();
                } catch (MalformedURLException e) {
                    System.out.println("Cannot create URL for: " + filename);
                    System.exit(0);
            // BBBBBB
            return url;
        // podi 3 End
    } //public class eka ***-Blaise

  • Xml dom parse

    Hi,
    i try to read an xml file using DOM parser. Icompil but not execute cause I have the follow error:
    org.apache.xerces.util.ObjectFactory$ConfigurationError: Provider org.apache.xerces.parsers.StandardParserConfiguration not found
         at org.apache.xerces.util.ObjectFactory.newInstance(ObjectFactory.java:298)
    The code corresponding is:
    import org.apache.xerces.parsers.*; // Apache Xerces parser classes
    import org.xml.sax.*; // Xerces DOM parser uses some SAX classes
    import org.w3c.dom.*; // Core DOM classes
    DOMParser parser = new org.apache.xerces.parsers.DOMParser();
    I have this class in my lib.
    If someone can help me...

    My guess is its not in your classpath. Don't know what you mean, "its in my lib.". Tomcat lib, jdk lib??? Just putting it in the java lib doesnt add it to the classpath. If it is in the classpath, I would look in the jar and see if those classes are there. If not, you probably have the wrong version or have another version in the path that is conflicting, or overlaying. fyi, You can have two versions of the xerces in the classpath. This could cause all kinds of problems.
    My two cents,
    Brunky

  • XML DOM Parser Performance Enhancement

    Hello,
    I parsed an XML file with DOM Parser.
    When I read it (Which is successfully done) I see, in the debugging phase, that there are empty elements
    which might represent a space, tab or newline and that are considered childrenNodes.
    This actually cost us double time to run through everything.
    My main question is how to get rid of the unwanted childrenNodes in order to iterate less on each element?
    Thank you.

    According to the documentation, you should be able to call normalize() on either the document or the root element. In practice, I still have to iterate through the empty elements. Such is life.
    - Saish

  • SLOW XML DOM Parser

    Hi All,
    I am trying to a parse an XML File whose contents are given below:
    <?xml version="1.0"?>
    <inquiryresult sessionname="TheDataEnquiry" code="0" subcode="0">
    <indexqueryresult code="0" subcode="0" queryname="AISClient range query">
    <item objectname="Ncompass_SVS" mediastatus="m">
    <rfield name="Amount" value="79427"/>
    <rfield name="PostingDate" value="20030708"/>
    <rfield name="Account" value="79427"/>
    <rfield name="DRN" value="79427"/>
    </item>
    </indexqueryresult>
    </inquiryresult>
    In the above code i have to retrieve the "name" and "value" attributes of <rfield/> tag in each <item/>element.
    The PL/SQL Procedure i used for data extraction is:
    CREATE OR REPLACE PROCEDURE ParseXMLFile(xmlfile varchar2)
    IS
    p xmlparser.parser;
    doc xmldom.DOMDocument;
    nl2 xmldom.DOMNodeList;
    nl3 xmldom.DOMNodeList;
    n3 xmldom.DOMNode;
    n4 xmldom.DOMNode;
    e xmldom.DOMElement;
    len2 number;
    len3 number;
    attrname varchar2(100);
    attrval varchar2(100);
    BEGIN
    -- new parser
    p := xmlparser.newParser;
    -- parse input file
    xmlparser.parse(p, xmlfile);
    -- get document
    doc := xmlparser.getDocument(p);
    -- Free resources associated with the Parser as now it is no longer needed.
    xmlparser.freeParser(p);
    nl2 := xmldom.getElementsByTagName(doc, 'item');
    len2 := xmldom.getLength(nl2);
    -- loop through elements of item
    FOR k IN 0..len2-1 LOOP
    n3 := xmldom.item(nl2, k);
    nl3 := xmldom.getElementsByTagName(xmldom.makeElement(n3), 'rfield');
    len3 := xmldom.getLength(nl3);
    -- loop through elements of rfield
    FOR l IN 0..len3-1 LOOP
    n4 := xmldom.item(nl3, l);
    attrname := xslprocessor.valueOf(n4, '@name');
    attrval := xslprocessor.valueOf(n4, '@value');
    END LOOP;
    END LOOP;
    END;
    But as soon I Parse an XML File greater than 10 MB, it takes a lot of time and gives me the java out of memory error.
    Please advise me whether the above method I use to extract data from the XML file is efficient or not.
    Thank You,
    SUNIL BABU

    Hi,
    When compared with SAX parsers, DOM parsers are a bit slow. They are best suited for small sized XML documents, but still going ahead with it, I have a suggestion that might improve the performance if the time taken for parsing the document into a DOM is very less when compared with the time taken for getting the values by looping thro' the DOM nodes.
    Instead of finding the item nodes and then the rfield nodes you may directly check for them using the XPATH syntax like as follows
    -- Getting a list of the RFIELD nodes in the document using the XPATH syntax.
    v_nl := sys.xslprocessor.selectNodes(sys.xmldom.makeNode(v_doc),'/ITEM/RFIELD');
    that should help you in avoiding lot many loops there by decreasing the time taken.
    HTH
    Elango.

  • Error java.lang.OutOfMemoryError using XML DOM parser

    Hi everyone,
    We are using Oracle 8.1.7 on Windows NT and trying to load XML into Oracle using the DOM API through PL/SQL. This is the method provided in the ORACLE_HOME\ora817\xdk\plsql\demo\domsample.sql which uses the XMLPARSER and XMLDOM PL/SQL packages.
    Now this works fine with small files (not sure about the exact file size). But for big files, it gives an error,
    ORA-29554: unhandled Java out of memory condition
    ORA-29532: Java call terminated by uncaught Java exception: java.lang.OutOfMemoryError
    We have increased the JAVA_POOL_SIZE from the default 20MB to 50MB. Not sure whether increasing this value will solve our problem and whether it is advisable to increase it to a higher value. Can anyone help, please ???
    Thanks.

    Steve,
    Thanks for the response. Now we are getting different error. In one of the questions earlier posted, someone (I think Jon) noted that following error (the one we are getting) can be resolved by using JDK 1.1.8, is there any specific JDK pre-req for XML Parser 0.9.8.6?
    Is it possible, to enhance release notes for 0.9.8.6 to include
    a) Tips mentioned in your mail (i.e. putting oracle xml parser 2.0.x before Apache/OJSP xmlparserv2.jar
    b) Dependencies on specific version of JDK
    Once again thanks for the responding to the mail and will appreciate a help to resolve this current error.
    Thanks,
    Shree
    Actual error :
    java.lang.IllegalArgumentException: sun.io.CharToB
    yteUTF-8
    at sun.io.CharToByteConverter.getConverterClass(Compiled Code)
    at sun.io.CharToByteConverter.getConverter(Compiled Code)
    at java.io.OutputStreamWriter.<init>(Compiled Code)
    at org.apache.jserv.JServConnection.getWriter(Compiled Code)
    at oracle.xml.xsql.XSQLServletPageRequest.setupWriter(Compiled Code)
    at oracle.xml.xsql.XSQLServletPageRequest.setContentType(Compiled Code)
    at oracle.xml.xsql.XSQLPageProcessor.process(Compiled Code)
    at oracle.xml.xsql.XSQLServlet.doGet(Compiled Code)
    at javax.servlet.http.HttpServlet.service(Compiled Code)
    at javax.servlet.http.HttpServlet.service(Compiled Code)
    at org.apache.jserv.JServConnection.processRequest(Compiled Code)
    at org.apache.jserv.JServConnection.run(Compiled Code)
    at java.lang.Thread.run(Compiled Code)
    null

  • XML DOM Parser

    I donwloaded the XML Parser for Java V2. I am trying to run the sample program DOMSample.java. It gives me the element names from the xml but it does not give me the values.
    Can someone help. What could be wrong. The sample program seems to be correct.

    Hi,
    You have to get the TEXT children of an element and then use the getNodeValue() method on the text nodes.
    We are planning on providing more meaningful sample examples.
    Thanks,
    Oracle XML Team

  • Dom parser

    can any one provide me the best link to download xml dom parser in C???
    i have tried some but showing errors......
    thanks for help

    Why on earth are you posting this in a java forum? http://xerces.apache.org/xerces-c/
    - Saish

  • Parsing an xml file using xerces DOM  parser

    Hi
    I want to parse a simple xml file using DOM parser.
    The file is
    <Item>
         <SubItem>
              <title>SubItem0</title>
              <attr1>0</attr1>
              <attr2>0</attr2>
              <attr3>0</attr3>
         </SubItem>
         <SubItem>
              <title>SubItem1</title>
              <attr1>1</attr1>
              <attr2>0</attr2>
              <attr3>0</attr3>
         </SubItem>
         <SubItem>
              <title>SubItem2</title>
              <attr1>1</attr1>
              <attr2>1</attr2>
              <attr3>0</attr3>
              <SubItem>
                   <title>SubItem20</title>
                   <attr1>2</attr1>
                   <attr2>1</attr2>
                   <attr3>0</attr3>
              </SubItem>
              <SubItem>
                   <title>SubItem21</title>
                   <attr1>1</attr1>
                   <attr2>1</attr2>
                   <attr3>0</attr3>
              </SubItem>
         </SubItem>
    </Item>
    I just want to parse this file and want to store the values in desired datastructures,
    I am trying using DOM parser, since it gives a tree structure, which is ok in this case.
    public void init()
              InputReader ir     =new InputReader("Habsys");
              Document      doc     =ir.read("Habitat");
              System.out.println(doc);
              traverse(doc);
    private void traverse(Document idoc)
              NodeList lchildren=idoc.getElementsByTagName("SubItem");
              for(int i=0;i<lchildren.getLength();i++)
                   String lgstr=lchildren.item(i).getNodeName();
                   if(lgstr.equals("SubItem"))
                        traverse(lchildren.item(i));
    private void traverse (Node node) {
    int type = node.getNodeType();
    if (type == Node.ELEMENT_NODE)
    System.out.println ("Name :"+node.getNodeName());
    if(!node.hasChildNodes())
    System.out.println ("Value :"+node.getNodeValue());
    NodeList children = node.getChildNodes();
    if (children != null) {
    for (int i=0; i< children.getLength(); i++)
    traverse (children.item(i));
    But I am not getting required results, a lot of values I am getting as null
    Could anybody tell me how to retrieve the data from the xml file, I simply want to read data and store it in data structures. For eg, for tag Subitem with title as ' SubItem1' has attr1 as '1', attr2 as'0' and attr3 as '0'.
    Thanks
    Gaurav

    Check This Sample Code....
    public void amethod(){
    DocumentBuilderFactory dbf = null;
    DocumentBuilder docBuilder = null;
    Document doc = null;
    try{
         dbf = DocumentBuilderFactory.newInstance();
         db = dbf.newDocumentBuilder();
         doc = db.parse(New File("path/to/your/file"));
         Node root = doc.getDocumentElement();
         System.out.println("Root Node = " + root.getNodeName());
         readNode(root);
    }catch(FactoryConfigurationError fce){ fce.printStackTrace();
    }catch(ParserConfigurationException pce){  pce.printStackTrace();
    }catch(IOException ioe){  ioe.printStackTrace();
    }catch(SAXException saxe){  saxe.printStackTrace();
    private void readNode(Node node) {
    System.out.println("Current Node = " + node.getNodeName());
    readAttributes(node);
    readChildren(node);
    private void readAttributes(Node node) {
    if (!node.hasAttributes())
         return;
    System.out.println("Attributes:");
    NamedNodeMap attrNodes = node.getAttributes();
    for (int i=0; i<attrNodes.getLength(); i++) {
    Attr attr = (Attr)attrNodes.item(i);
    System.out.println(attr.getNodeName() + " => " + attr.getNodeValue());
    private void readChildren(Node node) {
    if (!node.hasChildNodes())
         return;
    System.out.println("Value/s:");
    NodeList childNodes = node.getChildNodes();
    for (int i=0; i<childNodes.getLength(); i++) {
    Node child = (Node)childNodes.item(i);
    if (child.getNodeType() == Node.ELEMENT_NODE) {
    readNode(child);
    continue;
    if (child.getNodeType() == Node.TEXT_NODE) {
    if (child.getNodeValue()!=null)
    System.out.println(child.getNodeValue());

  • Problem in parsing XML using DOM Parser.

    Hi,
    I am parsing an XML using DOM Parser.
    When i try to get attributes of a node, i dont get in the order it is written. For Eg. This the node:
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa">
    When i try to print the attribute values i should get in the order:
    News, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, 202, COGN-4MNMT3, aaaa
    BUT I AM GETTING IN THE ORDER:
    News, 202, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, aaaa, COGN-4MNMT3
    Is there any way to sort this problem out?
    Thanks and Regards,
    Ashok

    Hi Guys,
    Thanks a lot for your replies.
    But i want to keep all the values as attributes only.
    the XML file is as shown below:
    <Menu>
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa" children="3">
         <Level1 label="ING News" link="" level="1" uid="COGN-4MNN89" parentid="COGN-4MNMT3" children="3" >
              <Level2 label="All ING News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="2" uid="INGD-4MVTK2" parentid="COGN-4MNN89" children="0">
              </Level2>
    </Level1>
    </Level0>
    The code i was using to get attributes is:
    String strElementName = new String(node.getNodeName());
         // System.out.println("strElementName:"+node.getNodeName());
    NamedNodeMap attrs = node.getAttributes();
    if (attrs != null) {
    int iLength = attrs.getLength();
    for (int i = 0; i < iLength; i++) {
    String strAttributes = (String) attrs.item(i).getNodeName();
    String strValues = (String) attrs.item(i).getNodeValue();
    Also is it not possible to Enforce the order using some Schema/DTD in this case?
    TIA
    Ashok

  • How to get nodes and its attributes of an XML file usiong DOM parsing?

    how to get nodes and its attributes of an XML file usiong DOM parsing?
    i am new to XML parsing.......
    Thanking you........

    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;      ...
    //Setup the document
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
         Document doc = docBuilder.parse (new File("MY_XML_FILE.xml"));
    //get elemets by name
         String elementValue = doc.getElementsByTagName("MY_ELEMENT").item(0).getTextContent();
    //This method can return multiple nodes, in this instance I get item(0) , first nodeRead the api for other methods of getting data.

  • Java DOM Parser (XML)

    Could someone please give me a link where I can find a example of a DOM parser, w3c. That shows how to parse an xml string or file and build the tree then access parts of it? I cant find a basic example anywhere!

    Check this
    http://java.sun.com/xml/jaxp/dist/1.1/docs/tutorial/dom/1_read.html

  • How to Parse a string into an XML DOM ?

    Hi,
    I want to parse a String into an XML DOM. Not able to locate any parser which supports that. Any pointers to this?

    Download Xerces from xml.apache.org. Place the relevant JAR's on your classpath. Here is sample code to get a DOM document reference.
    - Saish
    public final class DomParser extends Object {
         // Class Variables //
         private static final DocumentBuilder builder;
         private static final String JAXP_SCHEMA_LANGUAGE =
             "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
         /** W3C schema definitions */
         private static final String W3C_XML_SCHEMA =
             "http://www.w3.org/2001/XMLSchema";
         // Constructors //
         static {
              try {
                   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                   factory.setNamespaceAware(true);
                   factory.setValidating(true);
                   factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                   builder = factory.newDocumentBuilder();
                   builder.setErrorHandler(new ErrorHandler() {
                       public void warning(SAXParseException e) throws SAXException {
                           System.err.println("[warning] "+e.getMessage());
                       public void error(SAXParseException e) throws SAXException {
                           System.err.println("[error] "+e.getMessage());
                       public void fatalError(SAXParseException e) throws SAXException {
                           System.err.println("[fatal error] "+e.getMessage());
                           throw new XmlParsingError("Fatal validation error", e);
              catch (ParserConfigurationException fatal) {
                   throw new ConfigurationError("Unable to create XML DOM document parser", fatal);
              catch (FactoryConfigurationError fatal) {
                   throw new ConfigurationError("Unable to create XML DOM document factory", fatal);
         private DomParser() {
              super();
         // Public Methods //
         public static final Document newDocument() {
              return builder.newDocument();
         public static final Document parseDocument(final InputStream in) {
              try {
                   return builder.parse(in);
              catch (SAXException e) {
                   throw new XmlParsingError("SAX exception during parsing.  Document is not well-formed or contains " +
                        "illegal characters", e);
              catch (IOException e) {
                   throw new XmlParsingError("Encountered I/O exception during parsing", e);
    }- Saish

  • Problem in parsing a xml string using dom parser

    i want to parse a Xml String using a Dom parser......the parse function in dom parser takes only input stream as argument.......so i made the code as
    InputStream inputstream = new StringBufferInputStream(XmlData) ;
    InputSource inputSource = new InputSource(inputstream );
    but saxexception is coming and also warning called
    "java.io.StringBufferInputStream in java.io has been deprecated"
    please help me.........

    i want to parse a Xml String using a Dom
    parser......the parse function in dom parser takes
    only input stream as argument.......This is not true of the DOM parser in Java 1.4. So you might want to get rid of your old parser and replace it by something more current. Or perhaps you are using 1.4 and you just didn't read all of the API docs.

  • Parsing an XML using DOM parser in Java in Recursive fashion

    I need to parse an XML using DOM parser in Java. New tags can be added to the XML in future. Code should be written in such a way that even with new tags added there should not be any code change. I felt that parsing the XML recursively can solve this problem. Can any one please share sample Java code that parses XML recursively. Thanks in Advance.

    Actually, if you are planning to use DOM then you will be doing that task after you parse the data. But anyway, have you read any tutorials or books about how to process XML in Java? If not, my suggestion would be to start by doing that. You cannot learn that by fishing on forums. Try this one for example:
    http://www.cafeconleche.org/books/xmljava/chapters/index.html

Maybe you are looking for