Common XML entry titles (4)

Source: Internet
Author: User
Tags processing instruction xml example
In the XML object model, how does one deal with vacant characters? In some cases, the XML object model displays TEXT nodes that contain vacant characters. After the vacant characters are truncated, it may cause some confusion. For example, the following XML example shows the reference content:

In the XML object model, how does one deal with vacant characters?

In some cases, the XML object model displays TEXT nodes that contain vacant characters. After the vacant characters are truncated, it may cause some confusion. For example, the following XML example:

Reference content is as follows:
]>
Smith
John


The following trees are born:

Reference content is as follows:
Processing Instruction: xml
DocType: person
ELEMENT: person
TEXT:
ELEMENT: lastname
TEXT:
ELEMENT: firstname
TEXT:

Both the first and last names are TEXT nodes that only contain vacant characters. because the content model of the "person" element is MIXED, it contains the key word # PCDATA. The MIXED content model specifies that text can exist between elements. Therefore, the following content is accurate:

My last name is Smith and my first name is John

The result is similar to the following tree:

Reference content is as follows:
ELEMENT: person
TEXT: My last name is
ELEMENT: lastname
TEXT: and my first name is
ELEMENT: firstname
TEXT:

The sentence cannot be understood if there are no vacant characters after the word "is" and before the word "and. Therefore, for the MIXED content model, text combinations, vacant characters, and elements are all coherent. This is not the case for non-MIXED content models.

To remove TEXT nodes with only vacant characters, delete the # PCDATA keyword from the "person" element declaration:

The result is the following clear tree:

Reference content is as follows:

Processing Instruction: xml
DocType: person
ELEMENT: person
ELEMENT: lastname
ELEMENT: firstname

What is XML declaration?

The XML declaration must be listed at the top of the XML document:

It specifies the following project:

This document is an XML document. When the MIME type is lost or has not been specified, the MIME detector can use it to detect whether the file is of the text/xml type.

The document complies with the XML 1.0 specification. This is important when other versions of XML are available in the future.

Document character encoding. Encoding properties are optional and the default is UTF-8.

Note: the XML declaration must be in the first line of the XML document, so the following XML file:

The following analysis error is generated:

Invalid xml declaration.

Row 0000002:

Status 0000007: ------ ^

Note: XML declaration is optional. If you need to specify comments or processing instructions at the top, do not put them in XML declaration. However, the default encoding is the UTF-8.

How can I print my XML documents in a readable format?

When the DOM is used to create an XML file from the beginning of a document, any content is on a line with no space between them. This is the default action.

The default XSL style table in Internet Explorer 5 to display and print XML documents in a readable format. For example, if IE5 has been installed, check the nospace. xml file. The following tree should be displayed in the browser:

Reference content is as follows:
-
-
XYZ
12.56

No vacant characters are inserted in XML.

Printing readable XML is very interesting, especially when you have a DTD that defines different types of content models. For example, a space cannot be inserted in a hybrid content model (# PCDATA) because it may change the meaning of the content. For example, consider the following XML:

Elephant

It is better not to output:

E

Lephant

Because the word boundary is no longer accurate.

All of these make active printing the title. If you do not need to print readable XML, you can use DOM to insert vacant characters as text nodes in a proper position.

How to apply a namespace in a DTD? To apply a namespace in a DTD, declare it in the ATTLIST declaration of the element that applies it, as shown below:

The namespace type must be # FIXED. The property namespace is also like this:

Namespace and XML architecture

The DTD and XML architectures cannot be mixed. For example

Xmlns: x CDATA # FIXED "x-schema: myschema. xml"

Will not apply the schema definition defined in myschema. xml. Applications of the DTD and XML architectures are mutually exclusive.

How to apply XMLDSO in Visual Basic?

The following XML is used as an example:

Reference content is as follows:
Mark Hanson
206 765 4583
  
Jane Smith
425 808 1111

You can bind to the ADO record set as follows:

Create a New Visual Basic 6.0 project.

Add references to Microsoft ActiveX Data Objects 2.1 or later, Microsoft Data Adapter Library, and Microsoft XML 2.0.

Use the following code to load the XML data to the xml dso control:

Reference content is as follows:
Dim dso As New XMLDSOControl
Dim doc As IXMLDOMDocument
Set doc = dso. XMLDocument
Doc. Load ("d: \ test. xml ")

Use the following code to map DSO to the new record set object of the application DataAdapter:

Reference content is as follows:
Dim da As New DataAdapter
Set da. Object = dso
Dim rs As New ADODB. Recordset
Set rs. DataSource = da

Visit data:

MsgBox rs. Fields ("name"). Value

Result display string "Mark Hanson"

How to apply xml dom in Java?

The IE5 version of MSXML. DLL must be installed. In Visual J 6.0, select Add COM package from the project menu, and then select Microsoft XML 1.0 from the COM object list ". This control will structure the required Java wrapper into a new software package called "msxml. These pre-structured Java wrappers can also be downloaded. Class can be applied as follows:

Reference content is as follows:
Import com.ms.com .*;
Import msxml .*;
Public class Class1
{
Public static void main (String [] args)
{
DOMDocument doc = new DOMDocument ();
Doc. load (new Variant ("file: // d:/samples/ot. xml "));
System. out. println ("Loaded" doc. getDocumentElement (). getNodeName ());
}
}

The code example loads the 3.8 MB test file "ot. xml" from the sun religion example ". The Variant class is used to encapsulate basic Win32 VARIANT types.

Since a new package is actually obtained for each retrieval node, pointer matching cannot be applied on the node. Therefore, do not apply the following code,

Reference content is as follows:
IXMLDOMNode root1 = doc. getDocumentElement ();
IXMLDOMNode root2 = doc. getDocumentElement ();
If (root1 = root2 )...

Apply the following code:

If (ComLib. isw.unknown (root1, root2 ))....

The total size of the. class package is approximately 160KB. However, to fully comply with W3C specifications, only the IXMLDOM * package should be applied. The following classes are the old IE 4.0 XML interface, which can be deleted from the msxml folder:

Reference content is as follows:
IXMLAttribute *,
IXMLDocument *, XMLDocument *
IXMLElement *,
IXMLError *,

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.