Results 1 to 6 of 6

Thread: xml parsing

  1. #1
    gaurav65176 is offline Member
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Post xml parsing

    i am getting null pointer exception when i tried to parse the xml using DOMParser i have checked the xsd file my xml is exactly the same. can anybody solve this problem its realy urgent and dont known where the error is. the code which iam using is
    lsprSaxXmlParser=new DOMParser();
    lsprSaxXmlParser.parse(new inputsource(new StringReader (StringBuffer.toString)));
    i checked string buffer string reader and inputsource all of them has values in it
    iam getting this error
    java.lang.NullPointerException
    at org.apache.xerces.framework.XMLParser.parse(XMLPar ser.java:1094)

  2. #2
    tomhanks1984 is offline Member
    Join Date
    May 2008
    Posts
    4
    Rep Power
    0

    Default

    Hi,

    Am using dom parser to parse XML document. Am getting the following error while executing the parser class.
    "Element type FirstName is not declared".
    Can one tell me what causes this problem?

  3. #3
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    We need to see some code...!!
    Did this post help you? Please me! :cool:

  4. #4
    tomhanks1984 is offline Member
    Join Date
    May 2008
    Posts
    4
    Rep Power
    0

    Default Xml parsing

    Hi,

    I have attached the Xml Schema definition and XML document for you.

    Please go through and let me know where the issue exactly is...

    Thanks in advance :)
    Attached Files Attached Files

  5. #5
    Join Date
    Oct 2008
    Posts
    1
    Rep Power
    0

    Default Hello

    Hello Java Community Forum,

    This Bibhu Parasad new to such a big forum.I am happy with joining this site for communicating with all java professionals.

    Regards
    Bibhu

  6. #6
    pankaj_salwan is offline Member
    Join Date
    Jul 2008
    Location
    india
    Posts
    35
    Rep Power
    0

    Smile

    @gaurav


    ...see this code..hope it will help u..

    //use document builder

    File file = new File("mytext1.xml");
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(file);
    doc.getDocumentElement().normalize();
    System.out.println("Root element:-" + doc.getDocumentElement().getNodeName());
    NodeList nodeLst = doc.getElementsByTagName("article");
    f
    System.out.println("--------Information of all Data-------");
    log.debug("The Information of all the data is ");
    for (int s = 0; s < nodeLst.getLength(); s++)
    {
    double sum=0.0;
    Node fstNode = nodeLst.item(s);
    if (fstNode.getNodeType() == Node.ELEMENT_NODE)
    {
    Element fstElmnt = (Element) fstNode;
    NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("title");
    Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
    NodeList fstNm = fstNmElmnt.getChildNodes();
    System.out.println("Bill Value : " + ((Node) fstNm.item(0)).getNodeValue());
    log.debug("Bill Value : " + ((Node) fstNm.item(0)).getNodeValue());

    String str=((Node) fstNm.item(0)).getNodeValue();
    sum=sum+Double.valueOf(str.trim()).doubleValue();
    //System.out.println("sum=" +sum);

Similar Threads

  1. Parsing URL in Java
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:14 PM
  2. Using SAXParserFactory for parsing XML
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-20-2008, 09:42 AM
  3. Parsing URL
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-26-2007, 10:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •