当前位置:网站首页>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 .
边栏推荐
- Generate XML elements
- 测试工程师如何“攻城”(上)
- mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
- 1007 Maximum Subsequence Sum(25 分)(PAT甲级)
- Use canal and rocketmq to listen to MySQL binlog logs
- C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
- 基于NCF的多模块协同实例
- 2019年蜀山区第十五届青少年信息学竞赛
- How test engineers "attack the city" (Part 2)
- Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
猜你喜欢
Use canal and rocketmq to listen to MySQL binlog logs
MySQL数据库基本操作-DDL | 黑马程序员
Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
Go microservice (II) - detailed introduction to protobuf
Lm10 cosine wave homeopathic grid strategy
LeetCode第300场周赛(20220703)
PolyFit软件介绍
整理混乱的头文件,我用include what you use
读写关闭的channel是啥后果?
在线文本行固定长度填充工具
随机推荐
1006 Sign In and Sign Out(25 分)(PAT甲级)
Shell 编程核心技术《四》
自由小兵儿
Unity editor extends C to traverse all pictures in folders and subdirectories
Unity adds a function case similar to editor extension to its script, the use of ContextMenu
876. Intermediate node of linked list
测试工程师如何“攻城”(下)
Using SSH
升级智能开关,“零火版”、“单火”接线方式差异有多大?
数组中的第K个最大元素
长城证券开户安全吗 买股票怎么开户
FPGA timing constraint sharing 01_ Brief description of the four steps
[release] a tool for testing WebService and database connection - dbtest v1.0
Other InterSystems%net tools
[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0
牛客小白月赛7 F题
性能优化之关键渲染路径
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
FPGA时序约束分享01_四大步骤简述
PolyFit软件介绍