Using Microsoft's Dom,
Msxml4
// Introduce msxml4.dll
# Import "C:/winnt.0/system32/msxml4.dll"
// Create the xmldomdocument pointer
Msxml2: ixmldomdocumentptr pxmldoc;
// Initialize the COM interface
: Coinitialize (null );
// Use a smart pointer to create an instance of the parser
Hresult hr;
HR = pxmldoc. createinstance (_ uuidof (msxml2: domdocument30 ));
// Load the file
Pxmldoc-> load ("F: // He. xml ");
// Search for a node named city in the tree. "//" indicates searching at any Layer
Msxml2: ixmldomelementptr childnode;
Childnode = (msxml2: ixmldomelementptr) (pxmldoc-> selectsinglenode ("// Author "));
// Obtain the node type
Msxml2: domnodetype nodetype;
Childnode-> get_nodetype (& nodetype );
// Node name
BSTR var;
Cstring name;
Childnode-> get_nodename (& var );
Name = (char *) (_ bstr_t) var;
// Node Value
Variant varval;
Childnode-> get_nodetypedvalue (& varval );
Cstring strvalue = (char *) (_ bstr_t) varval;
Read attributes:
// Store node attributes in the linked list
Msxml2: ixmldomnamednodemapptr pattrs = NULL;
Msxml2: ixmldomnodeptr pattritem;
Childnode = (msxml2: ixmldomelementptr) (pxmldoc-> selectsinglenode ("// num "));
Childnode-> get_attributes (& pattrs );
Long ncount;
Pattrs-> get_length (& ncount );
For (INT I = 0; I <ncount; I ++)
{
Pattrs-> get_item (I, & pattritem );
// You can use the get_nodename and get_nodetypedvalue functions to obtain the attribute name and attribute value.
// You can also directly obtain
Cstring strattrname = (char *) (_ bstr_t) pattritem-> nodename;
Cstring strattrvalue = (char *) (_ bstr_t) pattritem-> nodetypedvalue;
}
In addition
You can use MSXML dom
The process of creating a document object.
Hresult hr;
Ixmldomdocument * pxmldoc;
Ixmldomnode * pxdn;
HR = coinitialize (null); // initialization of COM
HR = cocreateinstance (clsid_dom document, null, clsctx_inpproc_server,
Iid_ixmldomdocument, (void **) & pxmldoc );
HR = pxmldoc-> QueryInterface (iid_ixmldomnode, (void **) & pxdn );
Use the createelement method in the document to create a node to load and save XML files. The load or loadxml method can be used to load an XML document from a specified URL. The save method is used to save the document to a specified location, and getelementsbytagname is used to obtain the node data.