Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 24th, 2006, 11:25 PM
Jethro
Guest
 
Posts: n/a
Default 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.

  #2  
Old July 25th, 2006, 09:55 AM
George Bina
Guest
 
Posts: n/a
Default 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.
  #3  
Old July 25th, 2006, 02:55 PM
Jethro
Guest
 
Posts: n/a
Default 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.
  #4  
Old July 26th, 2006, 05:35 PM
Ramya A
Guest
 
Posts: n/a
Default 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.
  #5  
Old July 26th, 2006, 05:35 PM
Ramya A
Guest
 
Posts: n/a
Default 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.
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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.
Post your question now . . .
It's fast and it's free

Popular Articles