[Experience] MSXML error handling code

Source: Internet
Author: User

When you use the MSXML component to handle XML document errors, you must provide detailed error information. Most of the Code is just a simple error message returned, and the SDK documentation does not provide a routine. In desperation, I have to turn to Google Code Search again. Fortunately, I will soon find a suitable routine and make some modifications, include in your own code library.

 

 

The error handling code is as follows:

 

 

Msxml2: ixmldomparseerror * pxmlerror = NULL; // for XML errors <br/> long nerrorcode = e_fail; // for error codes </P> <p> If (pxmllicensedoc-> loadxml (m_slicense )! = Variant_true) // failed to load the license <br/>{< br/> wstring wstrerr; <br/> (wstrerr ). assign (L "/R/N"); <br/> (wstrerr ). append (L "failed to load the license/R/N"); </P> <p> hR = pxmllicensedoc-> get_parseerror (& pxmlerror ); </P> <p> If (null! = Pxmlerror) <br/>{< br/> hR = pxmlerror-> get_errorcode (& nerrorcode); <br/> If (nerrorcode! = 0) <br/>{< br/> wstring wstrtmperr; <br/> hR = reporterror (& wstrtmperr, pxmlerror); <br/> (wstrerr ). append (wstrtmperr); <br/>}< br/> pxmlerror-> release (); <br/>}< br/> return-1; <br/>} // end if 

 

The following reporterror function generates a unified Error Report:

// Configure <br/> // -- function reporterror <br/> // configure <br/> // -- this function is used for reporting parsing errors which occur during the <br //> // loading of XML into a ixmldomdocument2ptr object. <br/> // -- parameters: <br/> // wostream & wout-> A wide output stream to whi Ch the Error Report will be output. <br/> // ixmldomparseerror * pxmlerror-> contains the error info. <br/> // configure <br/> hresult cgutil: reporterror (wstring * pwstrerr, msxml2: ixmldomparseerror * pxmlerror) <br/>{< br/> long line; <br/> long linepos; <br/> long errorcode; <br/> BSTR pbreason = NULL; <br/> hresult hr; </P> <p> If (NUL L = pxmlerror) <br/>{< br/> return e_invalidarg; <br/>}// end if </P> <p> hR = pxmlerror-> get_line (& line); <br/> If (succeeded (HR )) <br/>{< br/> hR = pxmlerror-> get_linepos (& linepos); <br/> If (succeeded (HR )) <br/>{< br/> hR = pxmlerror-> get_errorcode (& errorcode); <br/> If (succeeded (HR )) <br/>{< br/> hR = pxmlerror-> get_reason (& pbreason); <br/> If (succeeded (HR )) <br/> {<br/> (* pwstrerr) + = P Breason; <br/> If (line> 0) <br/>{< br/> (* pwstrerr ). append (L "error on line"); <br/> char num1 [10]; <br/> _ ITOA (line, num1, 10 ); <br/> bstr bs = _ com_util: convertstringtobstr (num1); <br/> (* pwstrerr ). append (BS); <br/> (* pwstrerr ). append (L ", position"); <br/> _ ITOA (linepos, num1, 10); <br/> BS = _ com_util: convertstringtobstr (num1 ); <br/> (* pwstrerr ). append (BS); <br/> (* pwstrerr ). append (L ". "); <Br/>}// end if <br/>} // end if </P> <p> If (null! = Pbreason) <br/> sysfreestring (pbreason); <br/> // end if </P> <p> return hr; <br/>}// end function reporterror 

 

The above code reference this link: http://www.google.com/codesearch/p? Hl = ZH-CN # ia8v4e3y9hq/ITTF/publiclyavailablestandards/c043931_ISO_IEC_14496-5_2001_Amd_9_2007_Reference_Software.zip % 7cm6aqbswoj78/Alibaba/systems/im1/IPMP-X/ipmp_reltool/cgutil. CPP & Q = MSXML % 20 loadxml % 20 LANG: C ++ & D = 9

 

Thanks again to Google for bringing useful information to us and giving programmers better learning opportunities and endless freedom!

Describe your new note here.

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.