Now the XML document application is particularly very much.
I have written an example I have written before and use it later.
Part 1: DOM parsing:
Overview: DOM parses will read a complete XML document to generate a tree. This will load all the XML documents to the inner. Therefore, the speed of the parsing will be slower.
1. How to load an XML file:
// Create a DOM, load an XML document
Msxml :: ixmldomdocumentptr pCommanddoc;
PCOMMANDDOC.CREATEINSTANCE (__ uuidof (msxml :: domdocument);
PCOMMANDDOC-> PUT_ASYNC (variant_false);
PCOMMANDDOC-> PUT_VALIDATEONPARSE (VARIANT_FALSE);
PCOMMANDDOC-> PUT_RESOLVEEXTERNALS (Variant_false);
PCOMMANDDOC-> PUT_PRESERVEWHITESPACE (Variant_true);
PCOMMANDDOC-> LOAD (file.getbuffer (0));
2. Find the specified node in the XML document:
//turn up
Msxml :: ixmldomnodeptr prootnode = pcommanddoc-> selectsinglenode ("root / record");
IF (ProTNode == Null)
{
Return;
}
3, get the properties of the node in the XML document
CString Strtemp;
Msxml :: ixmldomnamednodemapptr patts = null;
ProotNode-> Get_attributes (& PATTRS);
IF (patty == null)
{
Return;
}
Msxml :: ixmldomnodeptr prequesttypeattr = pattrs-> getqualifiedItem ("name", "");
_BSTR_T strrequesttype = prequesttypeattr-> getText ();
Strtemp = strrequesttype.operator char * ();
4, get the content of the node
_BSTR_T STRVISIPORT = PNODE-> GetText ();
5, set the contents of the node
HRESULT HR = PNODE-> PUT_TEXT (_BSTR_T (M_STRGATEWAYPASSWORD);
6, set an attribute content
IXmldomAttribute * PA = NULL;
BSTR = sysallocstring (l "attribute 1");
PXMLDOM-> CreateAttribute (BSTR, & PNODE);
VAR = variantstring (l "strin");
PA-> PUT_VALUE (VAR);
ProT-> SetAttributeNode (Pa, & PA1);
The second part, how to use SAX analysis
Overview: SAX uses loading, will break the XML document, load it into memory. Use the event notification to represent the node. It seems that there is no ability to write a document. Its speed is much better than DOM.
When using SAX, you need to overload an interface IsaxContentHandler in MSXML4.0.
After several functions overloaded, after the node is found, it will call these functions.