Skip to content Skip to sidebar Skip to footer

How To Parse The Xml Using Dom Parser

how to parser the following XML using DOM PARSER OKMohammadi Reyshahri &l

Solution 1:

Getting XML DOM element

public Document getDomElement(String xml) {
    Documentdoc=null;
    DocumentBuilderFactorydbf= DocumentBuilderFactory.newInstance();

    dbf.setCoalescing(true);
    try {

        DocumentBuilderdb= dbf.newDocumentBuilder();

        InputSourceis=newInputSource();
        is.setCharacterStream(newStringReader(xml));
        doc = db.parse(is);

    } catch (ParserConfigurationException e) {
        returnnull;
    } catch (SAXException e) {
        returnnull;
    } catch (IOException e) {
        returnnull;
    }

    return doc;

}

then I tried this and its worked

Documentdoc= parser.getDomElement(XMLString);
            NodeListnl= doc.getElementsByTagName("All_BookDetails");

            progressDialog.setCancelable(true);
            Elemente= (Element) nl.item(0);
            BookRating = (Integer.valueOf(parser.getValue(e,
                        "BookAuthor")));

            BookTitle = parser.getValue(e, "BookTitle");
            BookAuthor = parser.getValue(e, "BookAuthor");
            BookPublishDate = parser.getValue(e, "DatePublished");
            BookDescription = parser.getValue(e, "BookDescription");
            bookID = parser.getValue(e, "BookID");
            bookCode = parser.getValue(e, "BookID");
            bookPageCount = parser.getValue(e, "TotalPages");

Post a Comment for "How To Parse The Xml Using Dom Parser"