XML Getting Started FAQ (3)

Source: Internet
Author: User
Tags cdata error code object model reserved visual studio

How do I load documents with foreign and special characters?

Documents can contain foreign characters, such as:

Foreign characters (úóí?)

For example  TRIDACNA foreign characters must precede the escape sequence. Foreign characters can be UTF-8 encoded or specified in different encodings, as follows:

Foreign characters ( Tridacna)

You can now load the XML correctly.

Other characters are kept in XML and need to be handled in a different way. The following XML:

This &
Produces the following error:
Spaces are not allowed here.
Line 0000001:this & that
Location 0000012:----------^

Here & is part of an XML syntactic structure that cannot be interpreted as & if it is placed only inside an XML data source. You need to replace a special character sequence called "entity."

This &
The following characters require the corresponding entity:

< <
& &
> >
" "
' &apos;

Quotation marks are used as delimiters for property values in markup, so they are usually not used inside property values. For example, the following content will return an error:

The single quotes here are used both as property delimiters and in the property value itself. To correct this problem, you can change the property delimiter to double quotes:

Or you can escape the single quotation mark as an entity &apos;

Both of these methods return the property value, John's Stuff, through the GetAttribute method in the XML object model. Similarly, for double quotes, you can use the entity
"。
You can also handle special characters in element content by placing text in a CDATA section. Here's what's right:

In this example, the XML object model displays a CDATA node as a child node of an XML node, which returns a string

This & the is just "text" content.
As NodeValue.

How do I use the MSXML COM component in Visual Studio 6.0 c + +?

The easiest way to use the MSXML COM component in Visual C + + 6.0 is to use the #import directive:

#import "Msxml.dll" Named_guids no_namespace#import "Msxml.dll" Named_guids no_namespace
It defines all the ixml* interfaces and interface IDs so that they can be used in the application. You can also get the MSXML type library and header file (in English) from InetSDK, as well as the uuid.lib containing the class IIDs.

How do I use HTML entities in XML?

The following XML contains HTML entities:

The Copyright? Watts, Microsoft INC, All rights reserved.

It produces the following error:

Reference to undefined entity ' copy '.
Line: 1, Location: 23, error code: 0XC00CE002
The Copyright? 2000, ...
----------------------^

This is because XML has only five built-in entities. For more information about built-in entities, see how to load documents with foreign and special characters?

To use HTML entities, you need to define them with DTDs. For more information about DTDs, see the XML recommendations for the consortium. To use the DTD, include it directly in the DOCTYPE tag, as follows:

The Copyright? Watts, Microsoft INC, All rights reserved.

To load it, you need to turn off the Validateonparse property of the IXMLDOMDocument interface. Try pasting it into the Validator test page, turn off DTD validation, and then click Validate. Note that the document will be loaded and the copyright character will appear in the DOM tree at the end of the validator page.

If you have completed DTD validation, you must include the HTML entity that is the parameter entity in the existing DTD, as follows:

%htmlent;
%htmlent;

It will define all HTML entities so that they can be used in XML documents.

How do I handle whitespace characters in element content?

The XML DOM has three ways to access element text content:

Property behavior

NodeValue returns the original text content (including whitespace characters) on the text, CDATA, COMMENT, and PI nodes as specified in the original XML source. For the ELEMENT node and the DOCUMENT itself, null values are returned.

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.