Click to See Complete Forum and Search --> : SelectSingleNode
Stephane Blanc
August 1st, 2000, 11:23 AM
Does anyone can give me an example of using this method in COM IXMLDOMNode ?
I'm not able to get a result from this method, S_FALSE is always returned.
Kaushik Roy
August 3rd, 2000, 04:41 AM
U can vectorize a XML tree and use this code.
private Vector locateChildren(Element parentElement, String elementName)
{
Vector elements = new Vector();
NodeList tbChildren = parentElement.getChildNodes();
for(int j=0; j < tbChildren.getLength(); j++)
{
Node tbChildNode = tbChildren.item(j);
if( tbChildNode.getNodeName().equals(elementName) )
{
elements.add(tbChildNode);
}
}
return elements;
}
----------------- OR u can use the code below -------------
//*given an element name and its parent Element, the Element corresponding to the input element name is returned
private Element locateChild(Element parentElement, String elementName)
{
NodeList tbChildren = parentElement.getChildNodes();
for(int j=0; j < tbChildren.getLength(); j++)
{
Node tbChildNode = tbChildren.item(j);
if( tbChildNode.getNodeName().equals(elementName) )
{
return (Element)tbChildNode;
}
}
return null;
}
Stephane Blanc
August 3rd, 2000, 08:43 AM
thanks,
Yes this is a way to solve but you are coding what should be done by SelectSingleNode. I would like to use SelectSingleNode and not reimplement all DOM API
mburt99
February 14th, 2001, 12:08 PM
That other reply wasn't very useful, eh?
Your problem probably lies in your use of the XPath syntax. You must provide an XPath search string to find the node. XPath syntax is explained fairly well in the SDK's help file.
Here is a VB example:
' find this node:
'<root>
' ...many levels
' <Parent>
' <Child>
' <Grandchild Attribname = "AttribValue"/>
Dim Node As MSXML2.IXMLDOMElement
Dim SearchString As String
SearchString = "//Parent/Child/Grandchild [@AttribName = ""AttribValue""]"
Set Node = DomDocument.documentElement.selectSingleNode(SearchString)
Note that this only returns the first node of all matching nodes.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.