Re: XsltCompiledTransform question
- From: stcheng@xxxxxxxxxxxxxxxxxxxx (Steven Cheng [MSFT])
- Date: Fri, 20 Jun 2008 04:35:12 GMT
Hi Mark,
I think the different behavior in XmlNode.Select with "//b" like path might
be caused by the difference context between XmlNode and XmlDocument. Since
XmlDocument has an entireo DOM context(start from root). And the "//b" like
path may also require a search from root to all descendent nodes.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Thread-Topic: XsltCompiledTransform question<elqDW5WzIHA.2408@xxxxxxxxxxxxxxxxxxxx> <85E372C4-C273-4C72-
thread-index: AcjQnqeS97g6+D1NSG+IYJh/7hksDQ==
X-WBNR-Posting-Host: 65.55.21.8
From: =?Utf-8?B?TWFyaw==?= <mmodrall@xxxxxxxxxxxxx>
References: <9A461CA0-60F3-4653-BB20-065A8F554510@xxxxxxxxxxxxx>
decidedly
I was scratching my head as well. Our resident xpath/xslt guru here saw
"//b" as "descendent or self" which the XmlNode.SelectNodes() was
not doing as well. With my first doc, I got the same 2 results no matterdangling
which node I started with, so it was running back up to the root and then
traversing down.
Given the behavior we saw in xslt with dangling nodes, I was surprised to
find the XmlNode.SelectNodes() behaving it ways that seemed quite
inconsistent with that...
Thanks
Mark
"Martin Honnen" wrote:
Mark wrote:
From our prior discussion, I didn't know what to expect from the
before?node. In the case of the dangling (unrooted) element, selecting "//b"
essentially treated the dangling node as the root and found the child.
Is this a fundamentally different case that the one we talked about
The results astonish me.
Here is a test:
XmlDocument doc = new XmlDocument();
XmlElement foo = doc.CreateElement("foo");
foo.InnerXml = "<bar>baz</bar>";
XmlNode rootNode = foo.SelectSingleNode("/");
Console.WriteLine("rootNode.NodeType: {0}; LocalName: {1}",
rootNode.NodeType, rootNode.LocalName);
XPathNavigator fooNav = foo.CreateNavigator();
XPathNavigator rootNav = fooNav.SelectSingleNode("/");
Console.WriteLine("rootNav.NodeType: {0}; LocalName: {1}",
rootNav.NodeType, rootNav.LocalName);
Output for me with Visual Studio 2005:
rootNode.NodeType: Element; LocalName: foo
rootNav.NodeType: Element; LocalName: foo
So for the XPath API the dangling element node has itself as its root
node selected by the XPath "/". If you select "/*" then you get the
'bar' element as
XmlDocument doc = new XmlDocument();
XmlElement foo = doc.CreateElement("foo");
foo.InnerXml = "<bar>baz</bar>";
XmlNode rootElement = foo.SelectSingleNode("/*");
Console.WriteLine("rootElement.NodeType: {0}; LocalName:
{1}", rootElement.NodeType, rootElement.LocalName);
XPathNavigator fooNav = foo.CreateNavigator();
XPathNavigator rootElNav = fooNav.SelectSingleNode("/*");
Console.WriteLine("rootElNav.NodeType: {0}; LocalName:
{1}", rootElNav.NodeType, rootElNav.LocalName);
outputs
rootElement.NodeType: Element; LocalName: bar
rootElNav.NodeType: Element; LocalName: bar
That "/" selects an element node is rather odd in my view.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
.
- References:
- Re: XsltCompiledTransform question
- From: Martin Honnen
- Re: XsltCompiledTransform question
- From: Mark
- Re: XsltCompiledTransform question
- From: Martin Honnen
- Re: XsltCompiledTransform question
- From: Martin Honnen
- Re: XsltCompiledTransform question
- From: Mark
- Re: XsltCompiledTransform question
- Prev by Date: CheckSignature Slow!!
- Next by Date: Creating an XML document
- Previous by thread: Re: XsltCompiledTransform question
- Next by thread: Re: XsltCompiledTransform question
- Index(es):
Relevant Pages
|