[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Java NPE at node.getAttribute( )

  • To: xml-dev@l...
  • Subject: Java NPE at node.getAttribute( )
  • From: Nishi Prafull <nishiprafull@g...>
  • 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@g...>

getattribute java
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.

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.