selectSingleNode Method (and Repeating Table)

J

Juli V.

Can somebody, please, explain me the way of workin this method!

For example, in some cases (help examples) I can see syntax like this:

objXMLNode = XDocument.DOM.selectSingleNode("/employees/employee"); //
HERE!!!
XDocument.View.SelectNodes(objXMLNode);
objXMLNodes = XDocument.View.GetSelectedNodes();
if (objXMLNodes.Count > 0){
XDocument.UI.Alert(objXMLNodes(0).nodeName + "\n\n" +
objXMLNodes(0).text);
}

And in some another:

nodeselfilename =
XDocument.DOM.selectSingleNode("/my:myFields/my:FileName").text; //
ANOTHER!!!
XDocument.SaveAs(nodeselfilename);

So what is the point?? I can't catch it!

And now my problem:
I have Repeating Table, and want to extract the same values from text-field,
for example, "task" (it repeats several times)
So how should I achieve it? To get array, or something, with the values from
this field!

Thanx a lot for help!
 
S

Steve van Dongen [MSFT]

Can somebody, please, explain me the way of workin this method!

For example, in some cases (help examples) I can see syntax like this:

objXMLNode = XDocument.DOM.selectSingleNode("/employees/employee"); //
HERE!!!
XDocument.View.SelectNodes(objXMLNode);
objXMLNodes = XDocument.View.GetSelectedNodes();
if (objXMLNodes.Count > 0){
XDocument.UI.Alert(objXMLNodes(0).nodeName + "\n\n" +
objXMLNodes(0).text);
}

And in some another:

nodeselfilename =
XDocument.DOM.selectSingleNode("/my:myFields/my:FileName").text; //
ANOTHER!!!
XDocument.SaveAs(nodeselfilename);

So what is the point?? I can't catch it!

selectSingleNode searches for the first node that matches the XPath
you pass it. It returns a reference to the node or null if there is
no node matches the XPath.

selectSingleNode method
http://msdn.microsoft.com/library/en-us/xmlsdk/html/xmmthselectSingleNode.asp

XPath
http://msdn.microsoft.com/library/en-us/xmlsdk/html/conXPath.asp
And now my problem:
I have Repeating Table, and want to extract the same values from text-field,
for example, "task" (it repeats several times)
So how should I achieve it? To get array, or something, with the values from
this field!

It would look something like this in JScript. Other languages would
look much the same.

var tasks = new Array();

// Get all the task nodes
var nodes = XDocument.DOM.selectNodes("//my:task");
if (nodes != null)
{
var node = null;
var value;

// Don't really need to reset but might as well ensure we're
// at the beginning
nodes.reset();

// Get the first node
node = nodes.nextNode();

// Loop until there are no more nodes
while (node != null)
{
value = node.text;

/* do something, i.e. add to an array */
tasks.push(value);

// Move to next node
node = nodes.nextNode();
}
}

Regards,
Steve
 
J

Juli V.

Great thanx, Steve!
Your code works great! (minimum modification needed)

I understood this method at last!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top