Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Xpath still doesn't work even after specifying namespace.


Message #1 by "Rohit Arora" <rohit_arora@i...> on Thu, 6 Mar 2003 19:50:18 +0530
Hi Group,

	Can somebody point out why this xpath is not working. I have also declared
a namespacemanager but still it gives error
-----Namespace Manager or XsltContext needed. This query has a prefix,
variable, or user-defined function.

I can fetch what I want by using xml.schema namespace but I don't want to
use xml.schema class for this coz this xpath simplifies my work to great
deal.

The code snippet looks like this ---

XmlDocument xdSchemaDocument = new XmlDocument();
xdSchemaDocument.Load("D:\\BackupJIB\\feb21\\jib.xsd");
XmlNamespaceManager xnmNamespaceForxsdPrefix = new
XmlNamespaceManager(xdSchemaDocument.NameTable);
xnmNamespaceForxsdPrefix.AddNamespace("xsd","http://www.w3.org/2001/XMLSchem
a");
XmlNode xnDataTypeNodeFromXSD 
xdSchemaDocument.SelectSingleNode("//xsd:element[@name=\"ThreadId\"]");

----

I am just trying to fetch the element tag which has attribute name --
ThreadId

Regards
Rohit Arora
Intersolutions (P) Ltd
B - 21, Sector 58,
Noida - 201301
Tel : 91-2585703/04/05 Extn: 229

Message #2 by "Jonathan Larouche" <jlarouche@d...> on Fri, 7 Mar 2003 14:11:37
You only miss 1 parameters in your selectSingleNode() function

When using xmlNameSpace in Xpath query, you must set the 
XmlNamespaceManager as the second parameter of selectSingleNode()

Ex: 
XmlNode xnDataTypeNodeFromXSD = xdSchemaDocument.SelectSingleNode
("//xsd:element[@name=\"ThreadId\"]",xnmNamespaceForxsdPrefix);

PS: Dont forget to set the namespace in the XML document itself Ie: 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"

Regards
Jonathan

> Hi Group,

	Can somebody point out why this xpath is not working. I have also 
declared
a namespacemanager but still it gives error
-----Namespace Manager or XsltContext needed. This query has a prefix,
variable, or user-defined function.

I can fetch what I want by using xml.schema namespace but I don't want to
use xml.schema class for this coz this xpath simplifies my work to great
deal.

The code snippet looks like this ---

XmlDocument xdSchemaDocument = new XmlDocument();
xdSchemaDocument.Load("D:\\BackupJIB\\feb21\\jib.xsd");
XmlNamespaceManager xnmNamespaceForxsdPrefix = new
XmlNamespaceManager(xdSchemaDocument.NameTable);
xnmNamespaceForxsdPrefix.AddNamespace
("xsd","http://www.w3.org/2001/XMLSchem
a");
XmlNode xnDataTypeNodeFromXSD 
xdSchemaDocument.SelectSingleNode("//xsd:element[@name=\"ThreadId\"]");

----

I am just trying to fetch the element tag which has attribute name --
ThreadId

Regards
Rohit Arora
Intersolutions (P) Ltd
B - 21, Sector 58,
Noida - 201301
Tel : 91-2585703/04/05 Extn: 229

Message #3 by "Rohit Arora" <rohit_arora@i...> on Fri, 7 Mar 2003 21:33:33 +0530
thanks it worked, I saw it later. I defined the namespacemanager but didn't
used it but later i saw. Thanks 4 the help.

Regards
Rohit Arora
Intersolutions (P) Ltd
B - 21, Sector 58,
Noida - 201301
Tel : 91-2585703/04/05 Extn: 229

"And for those who want to get into the game industry: Never think you're
not good enough; make someone tell you."


-----Original Message-----
From: Jonathan Larouche [mailto:jlarouche@d...]
Sent: Friday, March 07, 2003 2:12 PM
To: ASP.NET
Subject: [aspx] Re: Xpath still doesn't work even after specifying
namespace.


You only miss 1 parameters in your selectSingleNode() function

When using xmlNameSpace in Xpath query, you must set the
XmlNamespaceManager as the second parameter of selectSingleNode()

Ex:
XmlNode xnDataTypeNodeFromXSD = xdSchemaDocument.SelectSingleNode
("//xsd:element[@name=\"ThreadId\"]",xnmNamespaceForxsdPrefix);

PS: Dont forget to set the namespace in the XML document itself Ie:
xmlns:xsd="http://www.w3.org/2001/XMLSchema"

Regards
Jonathan

> Hi Group,

	Can somebody point out why this xpath is not working. I have also
declared
a namespacemanager but still it gives error
-----Namespace Manager or XsltContext needed. This query has a prefix,
variable, or user-defined function.

I can fetch what I want by using xml.schema namespace but I don't want to
use xml.schema class for this coz this xpath simplifies my work to great
deal.

The code snippet looks like this ---

XmlDocument xdSchemaDocument = new XmlDocument();
xdSchemaDocument.Load("D:\\BackupJIB\\feb21\\jib.xsd");
XmlNamespaceManager xnmNamespaceForxsdPrefix = new
XmlNamespaceManager(xdSchemaDocument.NameTable);
xnmNamespaceForxsdPrefix.AddNamespace
("xsd","http://www.w3.org/2001/XMLSchem
a");
XmlNode xnDataTypeNodeFromXSD 
xdSchemaDocument.SelectSingleNode("//xsd:element[@name=\"ThreadId\"]");

----

I am just trying to fetch the element tag which has attribute name --
ThreadId

Regards
Rohit Arora
Intersolutions (P) Ltd
B - 21, Sector 58,
Noida - 201301
Tel : 91-2585703/04/05 Extn: 229



  Return to Index