Common XML entry titles (3)

Source: Internet
Author: User
How to load documents with foreign and special characters? The document can contain foreign characters, such as foreigncharacters (?) For example? The foreign character of the escape must be prefixed with the escape sequence. Foreign characters can be either UTF-8-encoded or specified with different encodings,

How to load documents with foreign and special characters?

A document can contain foreign characters, for example:

Foreign characters (úóí ?)

For example? The foreign character of the escape must be prefixed with the escape sequence. Foreign characters can be either UTF-8 encoded or specified with different encodings, as shown below:

Foreign characters (? Token)

Now you can accurately load XML.

Other characters are stored in XML and must be processed in different ways. The following XML:

This & that

The following error occurs:

Space is not allowed here.

Row 0000001: This & that

Status 0000012: ---------- ^

Here & is part of the XML syntax structure. if it is only placed inside the XML data source, it cannot be described &. You need to replace the special character sequence called "entity.

This & that

The following characters need corresponding entities:

Reference content is as follows:

<
&&
>
""
''

Quotation mark characters are used as delimiters to Mark attribute values. Therefore, they cannot be used within the attribute value. For example, the following content will return an error:

The single quotes are used as attribute delimiters and in the attribute value itself. To correct this title, you can replace the attribute delimiters with double quotation marks:

Or you can escape single quotes as entities'

Both methods return the attribute value John's Stuff through the getAttribute method in the XML object model. Similarly, for double quotes, you can apply the entity ".

You can also put the text in the CDATA section to process special characters in the element content. The following content is accurate:

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

This & that is just "text" content.

As nodeValue.

In Visual Studio 6.0 C, how does one apply the msxml com component?

In Visual C 6.0, the easiest way to apply the msxml com component M is to apply the # import command:

# Import "msxml. dll" named_guids no_namespace # import "msxml. dll" named_guids no_namespace

It defines all IXML * interfaces and Interface IDs so that they can be applied in the application. You can also obtain the MSXML library, header file (in English), and uuid. lib containing IIDs.

How to apply HTML entities in XML?

The following XML contains HTML objects:

Copyright? 2000, Microsoft Inc, All rights reserved.

It produces the following errors:

Reference undefined object 'copy '.

Row: 1, status: 23, error code: 0xC00CE002

Copyright? 2000 ,...

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

To apply HTML entities, you must use DTD to define them. For more information about DTD, see W3C XML recommendations ). To apply this DTD, directly include it in the DOCTYPE tag, as shown below:

Copyright? 2000, Microsoft Inc, All rights reserved.

To load it, you must close the validateOnParse attribute of the IXMLDOMDocument interface. Paste it to the Validator test page, disable DTD verification, and click verify ". Please note that the document will be loaded and the copyright characters will be displayed in the DOM tree at the end of the validator page.

If you have completed DTD verification, you must include the HTML entity as the parameter entity in the existing DTD, as shown below:

% HTMLENT;

% HTMLENT;

It defines all HTML entities so that they can be applied in XML documents.

How to deal with vacant characters in element content?

Xml dom has three methods to visit element text content:

Attribute action

NodeValue returns the original TEXT (including vacant characters) on the TEXT, CDATA, COMMENT, and PI nodes as specified in the original XML source ). For the ELEMENT node and DOCUMENT itself, a null value is returned.

Data is similar to nodeValue

TEXT repeat connection refers to multiple TEXT and CDATA nodes in the subtree and return the combined results.

Note: vacant characters include new lines, tabs, and spaces.

The nodeValue attribute usually returns the content of the original document, regardless of how the document is loaded and the current xml: space category.

The text property connection refers to all text in the subtree and expands the object. This is related to how the document loads and the current status of the preserveWhiteSpace switch is related to the current xml: space category, as shown below:

Reference content is as follows:

PreserveWhiteSpace = true when the document is loaded
PreserveWhiteSpace = true preserveWhiteSpace = false
Xml: space = preserve xml: space = default
Reserved reserved and truncated


PreserveWhiteSpace = false when the document is loaded
PreserveWhiteSpace = true preserveWhiteSpace = false
Xml: space = preserve xml: space = default
Semi-reserved semi-reserved and truncation semi-reserved and truncated

The reserved content is similar to the original text content in the original XML document. truncation means that leading and trailing spaces have been deleted, semi-reserved "important vacant characters" and normalized "unimportant vacant characters ". An important vacancy character is a vacancy character in the text content. The unimportant vacant characters are the vacant characters between tags, as shown below:

Reference content is as follows:
\ N
\ T Jane \ n
\ TSmith \ n

In this example, red is an insignificant vacancy character, while Green is an important vacancy character. because it is part of the text content, it has an important meaning that cannot be neglected. In this example, the text attribute returns the following results:

Status return value

Retain "\ n \ t Jane \ n \ tSmith \ n"

Keep and truncate "Jane \ n \ tSmith"

Semi-reserved "Jane Smith"

Semi-retained and truncated "Jane Smith"

Note that "semi-reserved" will normalize unimportant vacant characters, for example, new lines and tab characters will degrade to a single space. If you change the xml: space attribute and preserveWhiteSpace switch, different values are returned for the text attribute.

CDATA and xml: space = "preserve" subtree boundaries

In the following example, the content of the CDATA node or the "reserved" node is connected because they are not involved in the normalization of unimportant vacant characters. For example:

Reference content is as follows:

\ N
\ T Jane \ n
\ T Smith]> \ n

In this case, the vacant characters in the CDATA node are no longer "merged" with "unimportant" vacant characters and will not be truncated. Therefore, when "semi-retained and truncated", the following content is returned:

"Jane Smith"

Here, the unimportant vacant characters between tags will be included, regardless of the content of the CDATA node. If the following content is used to replace CDATA, similar results will be returned:

Smith

Entity is special

An object is loaded and analyzed as part of a DTD and displayed under the DOCTYPE node. They do not have to have any xml: space category. For example:

Reference content is as follows:
Jane \ n
\ T \ n
">
]>
& Jane;

Assume that preserveWhiteSpace = false (within the scope of the DOCTYPE tag), the unimportant vacant characters are lost when the entity is analyzed. The entity will not have any vacant character nodes. The tree will be similar:

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.