Altova Mailing List Archives


RE: [xml-dev] Java NPE at node.getAttribute( )

From: "John Rivett-Carnac" <jbrc@----------.--.-->
To: "'Nishi Prafull'" <nishiprafull@-----.--->
Date: 1/24/2005 11:43:00 PM
Not sure if this will help you, but this VBScript code works fine:

	dim oDoc : set oDoc = server.createobject("MSXML.DomDocument")

	oDoc.LoadXML "<applet><transport name='jrmp'/><transport
name='codebase'/></applet>"

	Dim nsr: set nsr = oDoc.DocumentElement
	Dim nodeList : set nodeList=nsr.selectNodes("/applet/transport")

	Dim node:  set node= nodeList.item(0)
	Dim trans_val1 : trans_val1 = node.getAttribute("name")


	Dim node1 :  set node1=nodeList.item(1)
	Dim trans_val2 : trans_val2 = node1.getAttribute("name")

	response.write "<br>Name of item(1)=" & trans_val1
	response.write "<br>Name of item(2)=" & trans_val2
 
So, the xpath part of the code works as I would expect. Maybe namespaces or
some other difference would explain your problem.

-----Original Message-----
From: Nishi Prafull [mailto:nishiprafull@g...] 
Sent: 24 January 2005 23:06
To: John Rivett-Carnac
Cc: xml-dev@l...
Subject: Re: [xml-dev] Java NPE at node.getAttribute( )

Hi John:
I tried your suggestion:
 NodeList nodeList=xmlDocument.selectNodes("/applet/transport", nsr);
  XMLElement  node=(XMLElement)nodeList.item(0);
  String trans_val1 = node.getAttribute("name");

But I still get a NPE at node.getAttribute("name").

Can you suggest anything?

Thanks.

On Mon, 24 Jan 2005 22:00:06 -0000, John Rivett-Carnac
<jbrc@b...> wrote:
> 
> I think you should get the "transport" nodes in a node collection, 
> then get the name attribute of each transport node:
> 
> NodeList nodeList=xmlDocument.selectNodes("/applet/transport", nsr); 
> XMLElement  node=(XMLElement)nodeList.item(0);
> String trans_val1 = node.getAttribute("name");
> 
>

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.