Search node in IXMLDOMDocument
-
Hi, I need a 'find method' which returns a node in a IXMLDOMDocument. Is there any easy way to achieve this? Any tutorials/links about this? Thanks in advance, Jens
You could try here Code Project[^] Or use the CP site search and look for "XML Document Wrapper" for instance. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain) -
You could try here Code Project[^] Or use the CP site search and look for "XML Document Wrapper" for instance. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)Hi Antony, I have used that wrapper class you suggested already. It had a 'find' function in it, but it's pretty strangely coded that part. When he finds it, he adds it to the root node. Not exactly what i wanted to do with it. It should return a CXMLNode* or NULL if not found.
-
Hi Antony, I have used that wrapper class you suggested already. It had a 'find' function in it, but it's pretty strangely coded that part. When he finds it, he adds it to the root node. Not exactly what i wanted to do with it. It should return a CXMLNode* or NULL if not found.
It was quite a while ago that I looked at that class, I just remembered that there was a
Find
implementation. If it generally finds a node then you ought to be able to change the function to return CXMLNode*.CXMLNode* CXMLNode::Find(CXMLNode* rootNode, LPCTSTR nodeName, LPCTSTR nodeText, LPCTSTR attribName, LPCTSTR attribValue)
Where it adds the node to the root replace
CXMLNode *pNode = new CXMLNode(Nodes[i]);
rootNode->Nodes.Add(pNode);with
return Nodes[i];
And right at the end of the function
Nodes[i]->Find(rootNode,nodeName,nodeText,attribName,attribValue);
}
return NULL;
}For your purposes you will probably not need to pass rootNode to the function and therefore all refrences to it can be removed. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain) -
Hi, I need a 'find method' which returns a node in a IXMLDOMDocument. Is there any easy way to achieve this? Any tutorials/links about this? Thanks in advance, Jens
JensB wrote: I need a 'find method' which returns a node in a IXMLDOMDocument Yes. SelectNodes() and SelectSingleNode() returns nodes matching an XPath statement. JensB wrote: Any tutorials/links about this? Tons. Try some of the sites listed at the bottom of this page. Also try GOOGLE: XML XPath tutorial reference
"No matter where you go, there your are." - Buckaroo Banzai
-pete
-
JensB wrote: I need a 'find method' which returns a node in a IXMLDOMDocument Yes. SelectNodes() and SelectSingleNode() returns nodes matching an XPath statement. JensB wrote: Any tutorials/links about this? Tons. Try some of the sites listed at the bottom of this page. Also try GOOGLE: XML XPath tutorial reference
"No matter where you go, there your are." - Buckaroo Banzai
-pete
-
Hi. Is it easy to integrate XPath functions into regular XML files? selectNodes() is not a member function of IXMLDocument for example
JensB wrote: Is it easy to integrate XPath functions into regular XML files? I don't know what you mean. If you are using any parser that supports XPath queries ( MSXML does ) then it is integrated for you. You construct the XPath statement through whatever means is required to solve the current problem. You provide the statement as a text string to the parser engine (with MSXML it is the IXMLDOMDocument::SelectNodes() and SelectSingleNodes() methods) and it returns a node list of all nodes matching the XPath statement. JensB wrote: selectNodes() is not a member function of IXMLDocument for example It is a member of IXMLDOMDocument. It inherits that method as well as selectSingleNode() from the IXMLDOMNode interface. That allows you to execute relative XPath statements. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmmthselectnodes.asp[^]
"No matter where you go, there your are." - Buckaroo Banzai
-pete
-
JensB wrote: Is it easy to integrate XPath functions into regular XML files? I don't know what you mean. If you are using any parser that supports XPath queries ( MSXML does ) then it is integrated for you. You construct the XPath statement through whatever means is required to solve the current problem. You provide the statement as a text string to the parser engine (with MSXML it is the IXMLDOMDocument::SelectNodes() and SelectSingleNodes() methods) and it returns a node list of all nodes matching the XPath statement. JensB wrote: selectNodes() is not a member function of IXMLDocument for example It is a member of IXMLDOMDocument. It inherits that method as well as selectSingleNode() from the IXMLDOMNode interface. That allows you to execute relative XPath statements. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmmthselectnodes.asp[^]
"No matter where you go, there your are." - Buckaroo Banzai
-pete