当前位置:网站首页>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 :
- A processing instruction ( Also known as goal ) The name of .
- 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()
orElement()
) Both accept namespaces as parameters . Only if it is not set in the class definitionNamespace
When parameters are , Will assign relevant elements toNamespace
. - 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 .
边栏推荐
- Jetpack Compose 教程
- .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
- 添加命名空间声明
- 1003 Emergency(25 分)(PAT甲级)
- 1011 World Cup Betting (20 分)(PAT甲级)
- 函数式接口
- Technology sharing | interface testing value and system
- Oracle with as ora-00903: invalid table name multi report error
- Shell programming core technology "four"
- Online text line fixed length fill tool
猜你喜欢
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
建立自己的网站(15)
性能优化之关键渲染路径
Hough transform Hough transform principle
Nebula importer data import practice
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
牛客小白月赛7 谁是神箭手
一文掌握数仓中auto analyze的使用
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
Detailed explanation of the binary processing function threshold() of opencv
随机推荐
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
Shell programming core technology "four"
IBM WebSphere MQ retrieving messages
英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
如何使用Async-Awati异步任務處理代替BackgroundWorker?
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
千万不要只学 Oracle、MySQL!
反射(一)
基于NCF的多模块协同实例
Download the first Tencent technology open day course essence!
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
Use canal and rocketmq to listen to MySQL binlog logs
1672. Total assets of the richest customers
In flinksql, in addition to data statistics, is the saved data itself a state
Caché WebSocket
1011 World Cup Betting (20 分)(PAT甲级)
Go微服务(二)——Protobuf详细入门
The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology
1005 Spell It Right(20 分)(PAT甲级)