search
HomeBackend DevelopmentXML/RSS TutorialFrequently asked questions about getting started with XML (3)

How to load documents with foreign and special characters?

 Documents can contain foreign characters, for example:


 foreign characters (úóí?)


 For example, foreign characters such as 磲 must be preceded by an escape sequence. Foreign characters can be UTF-8 encoded or specified with a different encoding, as shown below:


  foreign characters (磲)


  XML now loads correctly.

 Other characters are reserved in XML and need to be handled differently. The following XML:


This & that
produces the following error:
No spaces are allowed here.
  Line 0000001: This & that
  Position 0000012: ----------^


  Here & is part of the XML syntax structure. If it is only placed inside the XML data source, it cannot be interpreted as & . You need to replace special character sequences called "entities".

  This & that
  The following characters require corresponding entities:


  & &
 delimiter and therefore generally cannot be used inside an attribute value. For example, the following will return an error:

The single quote here is used both as an attribute delimiter and within the attribute value itself. In order to correct this problem, you can change the attribute delimiter to double quotes:

 Or you can escape the single quotes to the entity'

 Both of the above methods will return the attribute value John's Stuff through the getAttribute method in the XML object model . Likewise, for double quotes, you can use the entity

 ".

  You can also handle special characters in element content by placing the text in a CDATA section. The following is correct:

  In this example, the XML Object Model Display the CDATA node as the child node of the xml node, it will return the string


  This & that is just "text" content.
  as nodeValue

 How to use MSXML COM component in Visual Studio 6.0 C++?

 In Visual C++. The easiest way to use MSXML COM components in 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 IXML* interfaces and interface IDs, so you can Use them in your application. The MSXML type library and header files (in English) are also available from INETSDK, as well as uuid.lib which contains class IIDs.

  How to use HTML entities in XML?

  The following XML contains HTML entities. :

 Copyright ? 2000, Microsoft Inc, All rights reserved.

 It generates the following error:


  Reference to undefined entity 'copy'.

  Line: 1, Location: 23, Error code: 0xC00CE002
 Copyright ? 2000, ...

 --------------------------^



 This is because XML has only five built-in entities. Details about built-in entities. See How to load documents with foreign and special characters? To use HTML entities, they need to be defined with a DTD. For details on the DTD, see the W3C XML Recommendation (English). To use this DTD, please refer to it. Included in the DOCTYPE tag as follows: Copyright ? 2000, Microsoft Inc, All rights reserved.

To load it, you need to turn off the validateOnParse attribute of the IXMLDOMDocument interface. Try pasting it into the Validator test page. , turn off DTD validation, and then click Validate. Notice that the document loads and copyright characters appear in the DOM tree at the end of the validator page.

 If DTD validation has been completed, then the HTML entities as parameter entities must be included in the existing DTD as follows:

 %HTMLENT;
 %HTMLENT;

 It will define all HTML entities, to use them in XML documents.

  How to deal with whitespace characters in element content?

  XML DOM has three ways of accessing the textual content of elements:


  Property Behavior

  nodeValue Returns the original textual content (including whitespace characters) on TEXT, CDATA, COMMENT and PI nodes, as specified in the original XML source. For ELEMENT nodes and DOCUMENT itself, null is returned.


  Data Same as nodeValue

  Text Repeatedly connect multiple TEXT and CDATA nodes in the specified subtree and return the combined result.

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

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

 The text attribute connects all text in the specified subtree and expands the entity. This has to do with how the document is loaded, the current state of the PReserveWhiteSpace switch and the current xml:space scope, see below:

 preserveWhiteSpace = true when the document is loaded

preserveWhiteSpace=true  preserveWhiteSpace=true  preserveWhiteSpace=false  preserveWhiteSpace=false  

xml:space=preserve  xml:space=default  xml:space=preserve  xml :space=default

reserved reserved Preserve Preserve and truncate PreserveWhiteSpace = false when the document is loaded


preserveWhiteSpace=true preserveWhiteSpace=false preserveWhiteSpace=false

xml:space=preserve xml:space=default xml:space=preserve xml :space=default

Half-preserved Half-preserved and truncated Half-preserved Half-preserved and truncated

The reserved here means that the original text content is exactly the same as in the original XML document, and truncation means that leading and trailing spaces have been removed, Semi-preserved means that "significant whitespace characters" are preserved and "unimportant whitespace characters" are normalized. Important whitespace characters are whitespace characters within the text content. Unimportant whitespace characters are the whitespace characters between tokens, look like this:

 n
  t Janen

tSmith n

  In this example, red is unimportant whitespace characters that can be ignored, while green is The whitespace character is important because it is part of the text content and therefore has important meaning that cannot be ignored. So in this example, the text property returns the following:

Status return value

Keep "nt JanentSmith n"

Keep and truncate "JanentSmith"

Half-preserve Jane Smith "




Please note that "semi-preserved" will normalize unimportant whitespace characters, for example, newline and tab characters will be reduced to a single space. If you change the xml:space attribute and preserveWhiteSpace switch, the text properties will return correspondingly different values.

 CDATA and xml:space="preserve" subtree boundaries
 In the example below, the contents of CDATA nodes or "preserve" nodes will be concatenated because they do not participate in normalization of unimportant whitespace characters. For example:

  n

 t Jane n

 t  Smith  ]>n

 In this case, whitespace characters inside the CDATA node are no longer "merged" with "unimportant" whitespace characters and are not truncated. So the "semi-preserved and truncated" case will return the following:

   "Jane      Smith     

  Here, unimportant whitespace characters between the and tags will be included, regardless of the contents of the CDATA node. If you replace CDATA with the following, the same result will be returned:


  Smith 

  Entities are special

  Entities are loaded and parsed as part of the DTD, and are displayed under the DOCTYPE node. They don't have to have any xml:space scope. For example:

  Jane n
 tn

 ">

 ]>

 &Jane;



  Assuming preserveWhiteSpace=false (in DOCTYPE tag scope), unimportant whitespace characters are lost when parsing entities. Entities will not There are blank character nodes. The tree will look like:


  DOCTYPE foo

  ENTITY: Jane

  ELEMENT: name
  ELEMENT: title

  TEXT>:Software Design Engineer

  ELEMENT: foo
  ATTRI BUTE:xml :space="preserve"
  ENTITYREF: Jane


 Please note that the DOM tree exposed under the ENTITY node inside the DOCTYPE does not contain any WHITESPACE nodes. This means that the children of the ENTITYREF node do not have WHITESPACE nodes, even if the entity reference is in the xml The same goes for :space="preserve". Each instance of an ENTITY referenced in a given document usually has the same tree. If an entity must absolutely preserve whitespace characters, it must specify itself within itself. The xml:space attribute, or the document preserveWhiteSpace switch must be set to true.

 How to deal with whitespace characters in attributes?

 There are several ways to access the attribute value. The IXMLDOMAttribute interface has the nodeValue attribute, which is equivalent to the Microsoft extension. nodeValue and text properties. These properties return: The text returned by the property


 attrNode.nodeValue
 attrNode.value
 getAttribute("name") returns exactly the same content (and extended entities) as in the original document.
 attrNode.nodeTypedValue Null
 attrNode.text is the same as nodeValue except that leading and trailing whitespace characters have been truncated.


 The "XML Language" specification defines the following behavior for XML applications: Text returned by attribute type
CDATA ID, IDREF, IDREFS, ENTITY, ENTITIES, NOTATION, enumeration

Semi-normalized Full normalized

Semi-normalized here It means converting new lines and tab characters into spaces, but multiple spaces will not degenerate into one space.

The above is the content of the FAQ (3) for getting started with XML. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
RSS Documents: How They Deliver Your Favorite ContentRSS Documents: How They Deliver Your Favorite ContentApr 15, 2025 am 12:01 AM

RSS documents work by publishing content updates through XML files, and users subscribe and receive notifications through RSS readers. 1. Content publisher creates and updates RSS documents. 2. The RSS reader regularly accesses and parses XML files. 3. Users browse and read updated content. Example of usage: Subscribe to TechCrunch's RSS feed, just copy the link to the RSS reader.

Building Feeds with XML: A Hands-On Guide to RSSBuilding Feeds with XML: A Hands-On Guide to RSSApr 14, 2025 am 12:17 AM

The steps to build an RSSfeed using XML are as follows: 1. Create the root element and set the version; 2. Add the channel element and its basic information; 3. Add the entry element, including the title, link and description; 4. Convert the XML structure to a string and output it. With these steps, you can create a valid RSSfeed from scratch and enhance its functionality by adding additional elements such as release date and author information.

Creating RSS Documents: A Step-by-Step TutorialCreating RSS Documents: A Step-by-Step TutorialApr 13, 2025 am 12:10 AM

The steps to create an RSS document are as follows: 1. Write in XML format, with the root element, including the elements. 2. Add, etc. elements to describe channel information. 3. Add elements, each representing a content entry, including,,,,,,,,,,,. 4. Optionally add and elements to enrich the content. 5. Ensure the XML format is correct, use online tools to verify, optimize performance and keep content updated.

XML's Role in RSS: The Foundation of Syndicated ContentXML's Role in RSS: The Foundation of Syndicated ContentApr 12, 2025 am 12:17 AM

The core role of XML in RSS is to provide a standardized and flexible data format. 1. The structure and markup language characteristics of XML make it suitable for data exchange and storage. 2. RSS uses XML to create a standardized format to facilitate content sharing. 3. The application of XML in RSS includes elements that define feed content, such as title and release date. 4. Advantages include standardization and scalability, and challenges include document verbose and strict syntax requirements. 5. Best practices include validating XML validity, keeping it simple, using CDATA, and regularly updating.

From XML to Readable Content: Demystifying RSS FeedsFrom XML to Readable Content: Demystifying RSS FeedsApr 11, 2025 am 12:03 AM

RSSfeedsareXMLdocumentsusedforcontentaggregationanddistribution.Totransformthemintoreadablecontent:1)ParsetheXMLusinglibrarieslikefeedparserinPython.2)HandledifferentRSSversionsandpotentialparsingerrors.3)Transformthedataintouser-friendlyformatsliket

Is There an RSS Alternative Based on JSON?Is There an RSS Alternative Based on JSON?Apr 10, 2025 am 09:31 AM

JSONFeed is a JSON-based RSS alternative that has its advantages simplicity and ease of use. 1) JSONFeed uses JSON format, which is easy to generate and parse. 2) It supports dynamic generation and is suitable for modern web development. 3) Using JSONFeed can improve content management efficiency and user experience.

RSS Document Tools: Building, Validating, and Publishing FeedsRSS Document Tools: Building, Validating, and Publishing FeedsApr 09, 2025 am 12:10 AM

How to build, validate and publish RSSfeeds? 1. Build: Use Python scripts to generate RSSfeed, including title, link, description and release date. 2. Verification: Use FeedValidator.org or Python script to check whether RSSfeed complies with RSS2.0 standards. 3. Publish: Upload RSS files to the server, or use Flask to generate and publish RSSfeed dynamically. Through these steps, you can effectively manage and share content.

Securing Your XML/RSS Feeds: A Comprehensive Security ChecklistSecuring Your XML/RSS Feeds: A Comprehensive Security ChecklistApr 08, 2025 am 12:06 AM

Methods to ensure the security of XML/RSSfeeds include: 1. Data verification, 2. Encrypted transmission, 3. Access control, 4. Logs and monitoring. These measures protect the integrity and confidentiality of data through network security protocols, data encryption algorithms and access control mechanisms.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment