Re: XsltCompiledTransform question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
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>
<elqDW5WzIHA.2408@xxxxxxxxxxxxxxxxxxxx> <85E372C4-C273-4C72-

I was scratching my head as well. Our resident xpath/xslt guru here saw
"//b" as "descendent or self" which the XmlNode.SelectNodes() was
decidedly
not doing as well. With my first doc, I got the same 2 results no matter
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
dangling
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
before?

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/



.



Relevant Pages

  • Re: XsltCompiledTransform question
    ... Given the behavior we saw in xslt with dangling nodes, ... essentially treated the dangling node as the root and found the child. ... rootNode.NodeType: Element; LocalName: foo ... rootElement.NodeType: Element; LocalName: bar ...
    (microsoft.public.dotnet.xml)
  • Re: XsltCompiledTransform question
    ... In the case of the dangling (unrooted) element, selecting "//b" essentially treated the dangling node as the root and found the child. ... Console.WriteLine("rootNode.NodeType:; LocalName: ", rootNode.NodeType, rootNode.LocalName); ... rootElement.NodeType: Element; LocalName: bar ...
    (microsoft.public.dotnet.xml)
  • Re: learning how to write a good bass line
    ... > music, more than just playing root notes, which is what i ... Since you have a guitar background, I presume you're OK with composing ... The rest of the notes in the bar lead to the next root - the ... Thinking of the melody as stretching across five ...
    (alt.guitar.bass)
  • Re: learning how to write a good bass line
    ... Make the first note in the bar the ... The rest of the notes in the bar lead to the next root - the ... Thinking of the melody as stretching across five ...
    (alt.guitar.bass)
  • Re: What key?
    ... So the chords would be half a bar of A, half a bar of G, and a bar of D. Then it would be in D. ... If you are playing it as a C, which sounds ok, then guess what? ... Then the issue becomes: Where is the root? ... they finish on G. Listen to the background vocals: Aaaah aaaah aaaah. ...
    (alt.guitar.beginner)