当前位置:网站首页>Specify the character set to output

Specify the character set to output

2022-07-04 19:32:00 User 7741497

Specify the character set of the output

To specify the character set to be used in the output document , You can set Writer Example of Charset attribute . Options include “UTF-8”“UTF-16” as well as InterSystems IRIS Other character sets supported .

Writing the Prolog

XML Preface to the document ( The part before the root element ) Can contain document type declarations 、 Processing instructions and comments .

influence Prolog Properties of

stay writer In the example , The following properties affect prolog:

Charset

Control two things :XML The character set declaration in the declaration and ( Corresponding ) The character set encoding used in the output .

NoXmlDeclaration

Controls whether the output contains XML Statement . in the majority of cases , The default value is 0, This means that a declaration has been written . If no character set is specified , And the output is directed to a string or character stream , The default is 1, And don't write any declarations .

Generate document type declaration

Before the root element , Can contain document type declarations , This declaration declares the schema used in the document . To generate a document type declaration , Need to use WriteDocType() Method , This method has one required parameter and three optional parameters . For the purposes of this document , The document type declaration includes the following possible parts :

<!DOCTYPE doc_type_name external_subset [internal_subset]>

As shown here , The document type has a name , according to XML The rules , The name must be the name of the root element . Declarations can contain external subsets 、 Internal subset or both .

external_subset Some point to other places DTD file . The structure of this section is any of the following :

PUBLIC public_literal_identifier
PUBLIC public_literal_identifier system_literal_identifier
SYSTEM system_literal_identifier

here public_literal_identifier and system_literal_identifier Is included DTD uri String . Be careful ,DTD It can have both public identifier and system identifier . The following is an example of a document type declaration , It contains an external subset that uses both public and system identifiers :

<!DOCTYPE hatches <!ENTITY open-hatch
         PUBLIC "-//Textuality//TEXT Standard open-hatch boilerplate//EN"
         "http://www.textuality.com/boilerplate/OpenHatch.xml">>

internal_subset Part is a set of entity declarations . The following is an example of a document type declaration , It contains only a set of internal declarations :

<!DOCTYPE teams [ <!ENTITY baseball team (name,city,player*)>
                   !ENTITY name (#PCDATA)>
                   !ENTITY city (#PCDATA)>
                   !ENTITY player (#PCDATA)>
  ] >

WriteDocType() Method has four parameters :

  • The first parameter specifies the name of the document type , Used in this XML Use... In the document . This is necessary , And it must be effective XML identifier . This name must also be used as the name of the root level element in this document .
  • The optional second and third parameters specify the external part of the declaration , As shown below :

WriteDocType Parameters

The second parameter

The third parameter

Other parts

“publicURI”

null

PUBLIC “publicURI”

“publicURI”

“systemURI”

PUBLIC “publicURI” “systemURI”

null

“systemURI”

SYSTEM “systemURI”

  • The optional fourth parameter specifies the inner part of the declaration . If this parameter is not empty , Then enclose it in square brackets [] in , And appropriately placed at the end of the declaration . No other characters were added .

Write processing instructions

To write processing instructions XML, Please use WriteProcessingInstruction() Method , This method has two parameters :

  1. A processing instruction ( Also known as goal ) The name of .
  2. The instruction itself is a string .

This method writes the following to XML:

<?name instructions?>

for example , To write the following processing instructions :

<?xml-stylesheet type="text/css" href="mystyles.css"?>

So , Can be called as follows WriteProcessingInstruction() Method :

 set instructions="type=""text/css"" href=""mystyles.css"""
 set status=writer.WriteProcessingInstruction("xml-stylesheet", instructions)

Specify the default namespace

In the writer instance , You can specify the default namespace , This namespace applies only to non Namespace Parameter setting class . There are several options :

  • You can specify the default namespace in the output method . Four main output methods (RootObject()RootElement()Object() or Element()) Both accept namespaces as parameters . Only if it is not set in the class definition Namespace When parameters are , Will assign relevant elements to Namespace.
  • You can specify the overall default namespace for the writer instance . So , Please write an instance of DefaultNamespace Property specifies the value .
Class Writers.BasicDemoPerson Extends (%RegisteredObject, %XML.Adaptor)
{

Parameter XMLNAME = "Person";

Property Name As %Name;

Property DOB As %Date;

}

By default , If we only export such objects , We'll see the output as follows :

<?xml version="1.0" encoding="UTF-8"?>
<Person>
  <Name>Persephone MacMillan</Name>
  <DOB>1976-02-20</DOB>
</Person>

contrary , If we are in the writer instance take DefaultNamespace Set to "http://www.person.org", Then export an object , You will receive the output shown below :

<?xml version="1.0" encoding="UTF-8"?>
<Person xmlns="www.person.org">
  <Name>Persephone MacMillan</Name>
  <DOB>1976-02-20</DOB>
</Person>

In this case , <Person> The element uses the default namespace , Otherwise, it will not be assigned to the namespace .

原网站

版权声明
本文为[User 7741497]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207041746145966.html