当前位置:网站首页>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 .
边栏推荐
- Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
- Qt实现界面滑动切换效果
- 2022养生展,健康展,北京大健康展,健康产业展11月举办
- 牛客小白月赛7 E Applese的超能力
- 建立自己的网站(15)
- prometheus安装
- Shell programming core technology "I"
- C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
- Unity给自己的脚本添加类似编辑器扩展的功能案例ContextMenu的使用
- sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
猜你喜欢
牛客小白月赛7 谁是神箭手

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

LM10丨余弦波动顺势网格策略

【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案

升级智能开关,“零火版”、“单火”接线方式差异有多大?

How to use async Awati asynchronous task processing instead of backgroundworker?

2022CoCa: Contrastive Captioners are Image-Text Fountion Models

神经网络物联网平台搭建(物联网平台搭建实战教程)

大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行

千万不要只学 Oracle、MySQL!
随机推荐
Shell 編程核心技術《四》
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
1672. Total assets of the richest customers
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
升级智能开关,“零火版”、“单火”接线方式差异有多大?
Summary and sorting of 8 pits of redis distributed lock
Pytorch学习(四)
In flinksql, in addition to data statistics, is the saved data itself a state
矩阵翻转(数组模拟)
Generate XML elements
《工作、消费主义和新穷人》的微信读书笔记
One question per day (2022-07-02) - Minimum refueling times
Build your own website (15)
明明的随机数
性能优化之关键渲染路径
添加命名空间声明
How test engineers "attack the city" (Part 2)
《看完就懂系列》字符串截取方法substr() 、 slice() 和 substring()之间的区别和用法