Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Accessing attributes via XPath

2 views
Skip to first unread message

Jeremy

unread,
Jul 1, 2009, 4:01:37 AM7/1/09
to
Hi folks,

Just cutting my teeth a bit with MSXML, and came across an issue that
is confusing me.

Given the following XML fragment:

<parent>
<child>
<grandchild attrib1="test" />
</child>
</parent>

I have an IXMLDOMNodePtr pointing to <child>, and I want to grab the
value of attrib1 in <grandchild>.

I was expecting the XPath to feed to selectNodes() would be
"grandchild@attrib1", but this causes MSXML to throw an exception
(with no error info).

It turns out the correct XPath is "grandchild/@attrib1", and I was
confused why, since I'm sure I've seen tutorials using the first
format.

Many thanks,
Jeremy

Peter Flynn

unread,
Jul 1, 2009, 4:35:33 PM7/1/09
to

If the address is supposed to be an XPath expression, then the slash is
mandatory. I haven't seen a different (ie non-XPath) syntax that just
uses elementname@attribname but someone may well have invented one. If
you can find the page you think you've seen, it may just be a typo.

//Peter

0 new messages