"AGB" <ag*******@hotmail.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com...
I would like to load all the values in the Name nodes into a drop-down list box:
: : <OutlineCodeNames>
<OutlineCodeName>
<UID>23423523</UID>
<Name>Contract</Name>
: : methodNodes = rootNode.SelectNodes("OutlineCodeName");
SelectNodes( ) takes a string argument that needs to be an XPath
expression. You receive nothing back because when it processes
the XPath, ''OutlineCodeName'', it compares it to the document
element's name only. The document element's name had a trailing
-s, ''OutlineCodeNames'', which doesn't match.
If it's the Name grandchild element you want the inner text of, then
you need to write an XPath expression with what are called "location
steps" to reach the Name node. XPath is hierarchical, like your PC's
file system.
Start at the root, /OutlineCodeNames.
From all of the immediate children of OutlineCodeNames, you want
OutlineCodeName elements (and if there were elements with other
names they would be filtered out by this 'step'). This gives you the
XPath, /OutlineCodeNames/OutlineCodeName.
Taking another look at all of the immediate children of OutlineCodeName
(UID, Name, etc.), the element name you want to take in the next step
is Name. This gives you the XPath expression:
/OutlineCodeNames/OutlineCodeName/Name
If you plug that string into what you've passing to SelectNodes( )
you should receive an XmlNodeList with one XmlNode for each
<Name> element.
Then take each <Name> elements' FirstChild.Value and Add( )
the names to your DropDown. With the example XML document
this should give you items for ''Contract'' and ''Project Charge
Number''.
Alternately, you could also write the XPath expression this way,
/OutlineCodeNames/OutlineCodeName/Name/text( )
which will return you an XmlNodeList containing XmlText nodes,
from which you can directly take the Value from.
Further, if you're interested in all elements named <Name> you
can get all elements named <Name> no matter where they are
in the document using the descendant-or-self axis, //.
//Name/text( )
The drawback is its not as efficient, and it's less specific about
which <Name> elements it returns (although you can get more
specific, such as //OutlineCodeName/Name/text( ) to ensure it
only returns the text of <Name> elements that are direct children
of <OutlineCodeName> -- and get none that are the direct
children of <DraftEditor>.)
Derek Harmon