Currently, there are many XML document applications.
I post an example I have previously written for future use.
Part 1: Dom parsing:
Overview: Dom parsing reads a complete XML document and generates a structure tree. This will load all XML documents into the internal. Therefore, the resolution speed will be slower.
1. How to load XML files:
// Create a Dom and load the 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. Search for the specified node in the XML document:
// Find
MSXML: ixmldomnodeptr prootnode = pcommanddoc-> selectsinglenode ("root/record ");
If (prootnode = NULL)
{
Return;
}
3. Get the node attributes in the XML document.
Cstring strtemp;
MSXML: ixmldomnamednodemapptr pattrs = NULL;
Prootnode-> get_attributes (& pattrs );
If (pattrs = NULL)
{
Return;
}
MSXML: ixmldomnodeptr prequesttypeattr = pattrs-> getqualifieditem ("name ","");
_ Bstr_t strrequesttype = prequesttypeattr-> gettext ();
Strtemp = strrequesttype. Operator char *();
4. Get the node content
_ Bstr_t strvisiport = pnode-> gettext ();
5. Set node content
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 );
Proot-> setattributenode (Pa, & pa1 );
Part 2: How to use SAX Parsing
Overview: sax uses a load-type method that separates XML documents and loads them into memory. Event Notification is used to locate the node. It seems that there is no ability to write documents. It is much faster than Dom.
When using sax, You Need To overload an interface isaxcontenthandler in msxml4.0.
After several functions are reloaded, when the node is found, these functions will be called back.
I don't know how to apply this sax parsing mode. It just seems that this method may not work well for that
Parse XML documents with important structures.