当前位置:网站首页>Add namespace declaration
Add namespace declaration
2022-07-04 19:33:00 【User 7741497】
Add namespace declaration
Default behavior
stay %XML.Writer Namespace declarations are automatically inserted , Generate namespace prefix , And apply prefixes where appropriate . for example , The following class definitions :
Class Sample.Person Extends (%Persistent, %Populate, %XML.Adaptor)
{
Parameter NAMESPACE = "http://www.yaoxin.com";
}If you export multiple objects of this class , You will see something similar to the following :
DHC-APP> w ##class(Demo.XmlDemo).Obj2Xml(1)
<?xml version="1.0" encoding="UTF-8"?>
<Person xmlns="http://www.yaoxin.com">
<Name>yaoxin</Name>
<SSN>111-11-1117</SSN>
<DOB>1990-04-25</DOB>
<s01:Home xmlns="" xmlns:s01="http://www.yaoxin.com">
<Street>889 Clinton Drive</Street>
<City>St Louis</City>
<State>WI</State>
<Zip>78672</Zip>
</s01:Home>
<s01:Office xmlns="" xmlns:s01="http://www.yaoxin.com">
<Street>9619 Ash Avenue</Street>
<City>Ukiah</City>
<State>AL</State>
<Zip>56589</Zip>
</s01:Office>
<Spouse>
<Name> Puyi </Name>
<SSN>111-11-1115</SSN>
<FavoriteColors>
<FavoriteColorsItem>Red</FavoriteColorsItem>
<FavoriteColorsItem>Orange</FavoriteColorsItem>
<FavoriteColorsItem>Yellow</FavoriteColorsItem>
<FavoriteColorsItem>Green</FavoriteColorsItem>
</FavoriteColors>
</Spouse>
<FavoriteColors>
<FavoriteColorsItem>Red</FavoriteColorsItem>
<FavoriteColorsItem>Orange</FavoriteColorsItem>
<FavoriteColorsItem>Yellow</FavoriteColorsItem>
</FavoriteColors>
<Age>31</Age>
</Person> Namespace declarations are automatically added to each <Person> Elements . Only add it to the root directory of the document .
Add the declaration manually
You can control when namespaces are introduced XML Output . The following methods will affect the next element written ( But it will not affect any element after this element ). For convenience , Several of these methods add standard W3 The name space .
These methods are usually used to add namespace declarations to the root element of a document ; in other words , Calling RootObject() or RootElement() Call one or more of these methods before .
Be careful : None of these methods assign any elements to namespaces , And these namespaces will never be added as default namespaces . When generating specific elements , You need to specify the namespace it uses , As in the back “ Write the root element ” and “ Generate XML Elements ” Described in .
AddNamespace()
method AddNamespace(namespace As %String,
prefix As %String,
schemaLocation As %String) as %Status Add the specified namespace . here ,Namespace Is the namespace to add ,Prefix Is an optional prefix to the namespace ,schemaLocation Is an optional... Indicating the location of the corresponding architecture URI.
If no prefix is specified , Prefix will be automatically generated ( The format is S01、S02 etc. ).
The following example shows the effect of this method . First , hypothesis Person Class is assigned to a namespace ( In class parameters NAMESPACE). If... Is not called first AddNamespace() Method to generate the output of such an instance , You may receive the output shown below :
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Person xmlns="http://www.person.org">
<Name>Love,Bart Y.</Name>
... perhaps , Before writing the root element, call AddNamespace() Method :
set status=writer.AddNamespace("http:///www.person.org","p")If the root element is subsequently generated , The output is as follows :
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:p="http:///www.person.org">
<Person xmlns="http://www.person.org">
... perhaps , Suppose you are calling AddNamespace() Method specifies the third parameter , This parameter provides the location of the associated schema :
set status=writer.AddNamespace("http:///www.person.org","p","http://www.MyCompany.com/schemas/person.xsd")under these circumstances , If subsequently generated Root Elements , The output is as follows :
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:p="http:///www.person.org"
xsi:schemaLocation="http:///www.person.org http://www.MyCompany.com/schemas/person.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Person xmlns="http://www.person.org">
...AddInstanceNamespace()
method AddInstanceNamespace(prefix As %String) as %Status add to W3 Schema instance namespace . The prefix here is an optional prefix for this namespace . The default prefix is XSI.
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...AddSchemaNamespace()
method AddSchemaNamespace(prefix As %String) as %Status add to W3 Schema namespace . The prefix here is an optional prefix for this namespace . The default prefix is s.
<Root xmlns:s="http://www.w3.org/2001/XMLSchema">
...AddSOAPNamespace()
method AddSOAPNamespace(soapPrefix As %String,
schemaPrefix As %String,
xsiPrefix As %String) as %Status add to W3 SOAP Encoding namespace 、SOAP Schema namespace and SOAP Schema instance namespace . This method has three optional parameters : Prefixes for these namespaces . The default prefixes are SOAP-Enc、s and XSI.
<Root xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...AddSOAP12Namespace()
method AddSOAP12Namespace(soapPrefix As %String,
schemaPrefix As %String,
xsiPrefix As %String) as %Status add to W3 SOAP 1.2 Encoding namespace 、SOAP Schema namespace and SOAP Schema instance namespace .
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...You can use more than one of these methods . If you use multiple namespaces , Then the affected element will contain all declarations of the specified namespace .
Write the root element
Every XML The document must contain exactly one root element . There are two ways to create this element :
- The root element may correspond directly to an enabled InterSystems IRIS XML The object of .
In this case , Use RootObject() Method , This method will enable the specified XML The object of is written as the root element . The output includes all object references contained in the object . The root element gets the structure of the object , You cannot insert other elements. You can specify the name of the root element , You can also use enabled by XML The default value of the object definition of .
The previous example uses this technique .
- The root element may just be a wrapper for a set of elements ( It may be a group of support XML The object of ).
In this case , Use RootElement() Method , This method inserts the root level element with the specified name . If this document is indented , This method also increases the indentation level of subsequent operations .
Then call other methods to generate output for one or more elements in the root element . In the root directory , You can include the required elements in any order or logic of your choice . after , call EndRootElement() Method to close the root element .
In both cases , You can specify the namespace to be used for the root element , Only when XML There is no class for Namespace The namespace will only be applied if the parameter value .
please remember , If the document contains a document type declaration , Then DTD The name of must be the same as the name of the root element .
边栏推荐
- 1672. Total assets of the richest customers
- There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
- .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
- The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
- 爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
- 一文掌握数仓中auto analyze的使用
- How to use async Awati asynchronous task processing instead of backgroundworker?
- 整理混乱的头文件,我用include what you use
- The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
- ftp、sftp文件传输
猜你喜欢

一文掌握数仓中auto analyze的使用

Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?

Online text line fixed length fill tool

从实时应用角度谈通信总线仲裁机制和网络流控

联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点

Bi skills - permission axis
Summary and sorting of 8 pits of redis distributed lock

Opencv functions and methods related to binary threshold processing are summarized for comparison and use

YOLOv5s-ShuffleNetV2

One question per day (2022-07-02) - Minimum refueling times
随机推荐
The 15th youth informatics competition in Shushan District in 2019
Generate XML elements
Bi skills - permission axis
From automation to digital twins, what can Tupo do?
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
升级智能开关,“零火版”、“单火”接线方式差异有多大?
Nebula Importer 数据导入实践
MySQL数据库基本操作-DDL | 黑马程序员
Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
Stream流
牛客小白月赛7 F题
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
《工作、消费主义和新穷人》的微信读书笔记
[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0
Hough Transform 霍夫变换原理
Have you guys ever used CDC direct Mysql to Clickhouse
YOLOv5s-ShuffleNetV2
PolyFit软件介绍
FPGA timing constraint sharing 01_ Brief description of the four steps
Online sql to excel (xls/xlsx) tool