XML tutorial (2)

Source: Internet
Author: User

XML tutorial (2)

Author: I am a Chu madman

Download source code

I. Sax Architecture
Sax contains multiple handler processors, many of which process events when processing XML resources.
Contenthandler is the most important one. It is used to parse the XML document, while dtdhandler verifies the DTD file.
Msxml3 currently includes the following processors:

  • Imxattributes Interface
  • Imxwriter Interface
  • Isaxattributes Interface
  • Isaxcontenthandler Interface
  • Isaxdeclhandler Interface
  • Isaxdtdhandler Interface
  • Isaxentityresolver Interface
  • Isaxerrorhandler Interface
  • Isaxlexicalhandler Interface
  • Isaxlocator Interface
  • Isaxxmlfilter Interface
  • Isaxxmlreader Interface

Ii. isaxcontenthandler Interface
Contenthandler has the following functions:

Characters Enddocument Startdocument Endelement Startelement
Ignorablewhitespace Startprefixmapping Processinginstruction Skippedentity  

The functions to be explained today are characters, startdocument/enddoucment, and startelement/endelement functions. Their usage:

Iii. Function Description

Hresult characters ([in] const wchar_t * pwchchars, [in] int cchchars); pwchchars gets string information. Cchchars gets the length of the string.
Hresult startdocument (); this function indicates that the document is parsed.
Hresult startelement ([in] const wchar_t * pwchnamespaceuri, [in] int cchnamespaceuri, [in] const wchar_t * pwchlocalname, [in] int cchlocalname [in] const wchar_t * [in] int cchqname); [in] isaxattributes * pattributes); pwchnamespaceuri gets the namespace URI. Cchnamespaceuri gets the URI length. Pwchlocalname gets the tag. Cchlocalname gets the tag length. Obtain the QNAME from pwchqname. The length of the QNAME obtained by cchqname. Pattributes obtains the attribute information of an element.
Because the element attributes are not fixed, you need to obtain them using the following method. Pattributes-> getlength (& L); For (INT I = 0; I <L; I ++) {wchar_t * ln, * VL; int lnl, Vll; pattributes-> getlocalname (I, & ln, & lnl); PRT (L "% s =", LN, lnl); pattributes-> getvalue (I, & VL, & VLL); PRT (L "/" % S/"", VL, VLL );}

4. Use contenthandler:

Hero_xmlcontenthandler * phero_xml; isaxxmlreaderptr preader = NULL; hresult hr; CHR (preader. createinstance (_ uuidof (saxxmlreader); // only one content handler can be registered at a time. phero_xml = hero_xmlcontenthandler: createinstance (); // generate the hero_xmlcontenthandler object. CHR (preader-> putcontenthandler (phero_xml); // register the hero_xmlcontenthandler processor. CHR (preader-> parseurl (L "Hero. xml"); // resolution path. CHR (preader-> putcontenthandler (null ));


Program running diagram.

V. Postscript

I hope this article will help you. You are welcome to criticize and correct it. For more information, see the source code. The Development Kit is msxml3, and the principles of Apache xerces are also the same.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.