
July 24th, 2006, 11:25 PM
|
|
|
Why can I not XPath to this element in a schema
I've tried to find the simplest demonstration of my issue. I have
source XML that looks like this (not a real XSD schema, but it doesn't
matter at this point):
(in var xmlStr:)
<xsd:element
xmlns:xsd="http://www.w3.org/2001/XMLSchema">abab</xsd:element>
Essentially, it's just an xml node w/ an xsd prefix, and the namespace
defined right on the node. Then, some jibberish is the text of the
node ("abab"). Using .NET, if I load this XML into an XmlDocument like
this:
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlStr);
doc.SelectSingleNode("//xsd:element");
It tells me I need a namespace manager. So, I put one in my code like
this:
XmlNameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("xsd", "http://www.w3.org//2001/XMLSchema");
Then, I call .SelectSingleNode("//xsd:element", nsmgr). Now, it's
null! What in the world?!? I feel like I'm missing something trivial
here. "//element" is also null, but I expected that because of my
namespace.
|

July 25th, 2006, 09:55 AM
|
|
|
Re: Why can I not XPath to this element in a schema
<xsd:element
Quote:
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema">abab</xsd:element>
|
Quote:
|
nsmgr.AddNamespace("xsd", "http://www.w3.org//2001/XMLSchema");
|
----------------------------------------------^^
You have 2 forward slash characters in the second case, note .org//2001
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jethro wrote:
Quote:
I've tried to find the simplest demonstration of my issue. I have
source XML that looks like this (not a real XSD schema, but it doesn't
matter at this point):
>
(in var xmlStr:)
<xsd:element
xmlns:xsd="http://www.w3.org/2001/XMLSchema">abab</xsd:element>
>
Essentially, it's just an xml node w/ an xsd prefix, and the namespace
defined right on the node. Then, some jibberish is the text of the
node ("abab"). Using .NET, if I load this XML into an XmlDocument like
this:
>
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlStr);
doc.SelectSingleNode("//xsd:element");
>
It tells me I need a namespace manager. So, I put one in my code like
this:
>
XmlNameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("xsd", "http://www.w3.org//2001/XMLSchema");
>
Then, I call .SelectSingleNode("//xsd:element", nsmgr). Now, it's
null! What in the world?!? I feel like I'm missing something trivial
here. "//element" is also null, but I expected that because of my
namespace.
|
|

July 25th, 2006, 02:55 PM
|
|
|
Re: Why can I not XPath to this element in a schema
Thanks George. That was a typo. Anyone else?
George Bina wrote:
Quote:
Quote:
<xsd:element
xmlns:xsd="http://www.w3.org/2001/XMLSchema">abab</xsd:element>
|
>
Quote:
|
nsmgr.AddNamespace("xsd", "http://www.w3.org//2001/XMLSchema");
|
----------------------------------------------^^
You have 2 forward slash characters in the second case, note .org//2001
>
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
>
Jethro wrote:
Quote:
I've tried to find the simplest demonstration of my issue. I have
source XML that looks like this (not a real XSD schema, but it doesn't
matter at this point):
(in var xmlStr:)
<xsd:element
xmlns:xsd="http://www.w3.org/2001/XMLSchema">abab</xsd:element>
Essentially, it's just an xml node w/ an xsd prefix, and the namespace
defined right on the node. Then, some jibberish is the text of the
node ("abab"). Using .NET, if I load this XML into an XmlDocument like
this:
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlStr);
doc.SelectSingleNode("//xsd:element");
It tells me I need a namespace manager. So, I put one in my code like
this:
XmlNameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("xsd", "http://www.w3.org//2001/XMLSchema");
Then, I call .SelectSingleNode("//xsd:element", nsmgr). Now, it's
null! What in the world?!? I feel like I'm missing something trivial
here. "//element" is also null, but I expected that because of my
namespace.
|
|
|

July 26th, 2006, 05:35 PM
|
|
|
Re: Why can I not XPath to this element in a schema
Use Xpath in your SelectSingleNode call. Something like
doc.SelectSingleNode("Request/Element", nsmgr)
where xmlStr has the this node.
Post the contents of xmlStr to further help troubleshoot.
Ramya
Jethro wrote:
Quote:
Thanks George. That was a typo. Anyone else?
>
George Bina wrote:
Quote:
Quote:
<xsd:element
xmlns:xsd="http://www.w3.org/2001/XMLSchema">abab</xsd:element>
|
Quote:
|
nsmgr.AddNamespace("xsd", "http://www.w3.org//2001/XMLSchema");
|
----------------------------------------------^^
You have 2 forward slash characters in the second case, note .org//2001
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jethro wrote:
Quote:
I've tried to find the simplest demonstration of my issue. I have
source XML that looks like this (not a real XSD schema, but it doesn't
matter at this point):
>
(in var xmlStr:)
<xsd:element
xmlns:xsd="http://www.w3.org/2001/XMLSchema">abab</xsd:element>
>
Essentially, it's just an xml node w/ an xsd prefix, and the namespace
defined right on the node. Then, some jibberish is the text of the
node ("abab"). Using .NET, if I load this XML into an XmlDocument like
this:
>
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlStr);
doc.SelectSingleNode("//xsd:element");
>
It tells me I need a namespace manager. So, I put one in my code like
this:
>
XmlNameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("xsd", "http://www.w3.org//2001/XMLSchema");
>
Then, I call .SelectSingleNode("//xsd:element", nsmgr). Now, it's
null! What in the world?!? I feel like I'm missing something trivial
here. "//element" is also null, but I expected that because of my
namespace.
|
|
|
|

July 26th, 2006, 05:35 PM
|
|
|
Re: Why can I not XPath to this element in a schema
Use Xpath in your SelectSingleNode call. Something like
doc.SelectSingleNode("Request/Element", nsmgr)
where xmlStr has the this node.
Post the contents of xmlStr to further help troubleshoot.
Ramya
Jethro wrote:
Quote:
Thanks George. That was a typo. Anyone else?
>
George Bina wrote:
Quote:
Quote:
<xsd:element
xmlns:xsd="http://www.w3.org/2001/XMLSchema">abab</xsd:element>
|
Quote:
|
nsmgr.AddNamespace("xsd", "http://www.w3.org//2001/XMLSchema");
|
----------------------------------------------^^
You have 2 forward slash characters in the second case, note .org//2001
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jethro wrote:
Quote:
I've tried to find the simplest demonstration of my issue. I have
source XML that looks like this (not a real XSD schema, but it doesn't
matter at this point):
>
(in var xmlStr:)
<xsd:element
xmlns:xsd="http://www.w3.org/2001/XMLSchema">abab</xsd:element>
>
Essentially, it's just an xml node w/ an xsd prefix, and the namespace
defined right on the node. Then, some jibberish is the text of the
node ("abab"). Using .NET, if I load this XML into an XmlDocument like
this:
>
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlStr);
doc.SelectSingleNode("//xsd:element");
>
It tells me I need a namespace manager. So, I put one in my code like
this:
>
XmlNameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("xsd", "http://www.w3.org//2001/XMLSchema");
>
Then, I call .SelectSingleNode("//xsd:element", nsmgr). Now, it's
null! What in the world?!? I feel like I'm missing something trivial
here. "//element" is also null, but I expected that because of my
namespace.
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|