OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Java NPE at node.getAttribute( )

[ Lists Home | Date Index | Thread Index ]
  • To: xml-dev@lists.xml.org
  • Subject: Java NPE at node.getAttribute( )
  • From: Nishi Prafull <nishiprafull@gmail.com>
  • Date: Mon, 24 Jan 2005 11:17:24 -0800
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding; b=HjH5gATWDfBHrr4UFtS+xlltRal7Q7ODlVoWgX/0/IflKNttEp46OlyCfozhVG30rIVDU2wrNH3hJgRSR6iAQrfSJ+5rB2p44e0e1NQR9jXFUNt0s73y/wWtY0EwsnUsiKNsNdO9uzJ4hbyRiI91lsEG36fwcNj9phbS3dDXZ2Y=
  • Reply-to: Nishi Prafull <nishiprafull@gmail.com>

Hi:

If I have the following in my xml doc, 
<tptd:applet xmlns  tptd="http://www.oracle.com/tptd/configuration";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.oracle.com/tptd/configuration plus
_config.xsd">
<transport name="jrmp"/>
<transport name="codebase"/>.....
.....
</tptd:applet>

I want to extract the values of the "name" nodes and subsitute them as
values for the "name" nodes in another xml document. I have written
the following DOM Parser implementation but it gives me a Java NPE at
node.getAttribute().
Can someone please let me know what I am doing wrong here --

public void doSub() throws FileNotFoundException, IOException,
XSLException, InvocationTargetException, XMLParseException,
SAXException
  {
   URL in_xml_url = new URL("file://" + getSpec());
   FileOutputStream out_xml = new FileOutputStream(m_outfileSpec, false);

    XMLDocument xmlDocument = null;

    //Create a parser
    DOMParser parser = new DOMParser();

    parser.setValidationMode(XMLConstants.NONVALIDATING);
    parser.setBaseURL(in_xml_url);

    //Create a document from the url
    parser.parse(in_xml_url);

    //Cache the document from the parser
    xmlDocument = parser.getDocument();

    XMLElement nsr = (XMLElement) xmlDocument.getDocumentElement();

   //namespace resolver
    NodeList nodeList=xmlDocument.selectNodes("/applet/transport/@name", nsr);

    XMLElement  node=(XMLElement)nodeList.item(0);
    String trans_val1 = node.getAttribute("name"); //getting Java NPE here
    XMLElement  node1=(XMLElement)nodeList.item(1);
    String trans_val2 = node1.getAttribute("name");

      //subsitute in the new document
      parser.parse(new FileReader(m_outfileSpec));
      XMLDocument document1 =parser.getDocument();

      XMLElement nsr_new = (XMLElement) document1.getDocumentElement();

      NodeList nodeList1=document1.selectNodes("/configuration//plus/transport/@name",f);
         XMLElement  node2=(XMLElement)nodeList1.item(0);
         node2.setAttribute("name",trans_val1);
         XMLElement  node3=(XMLElement)nodeList.item(1);
         node3.setAttribute("name",trans_val2);
         document1.print(out_xml);
         out_xml.close();
  }


Thanks much.




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS