当前位置:网站首页>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 .
边栏推荐
- Online sql to excel (xls/xlsx) tool
- Summary and sorting of 8 pits of redis distributed lock
- Bi skills - permission axis
- 指定输出的字符集
- 每日一题(2022-07-02)——最低加油次数
- 2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
- There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
- 2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import 'fmt' func
- 1007 Maximum Subsequence Sum(25 分)(PAT甲级)
- Wechat reading notes of "work, consumerism and the new poor"
猜你喜欢

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

性能优化之关键渲染路径

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

There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks

"Only one trip", active recommendation and exploration of community installation and maintenance tasks

欧拉函数

MySQL数据库基本操作-DDL | 黑马程序员

node_exporter部署

One question per day (2022-07-02) - Minimum refueling times

Bi skills - permission axis
随机推荐
《看完就懂系列》字符串截取方法substr() 、 slice() 和 substring()之间的区别和用法
Use canal and rocketmq to listen to MySQL binlog logs
2022养生展,健康展,北京大健康展,健康产业展11月举办
From automation to digital twins, what can Tupo do?
Shell 编程核心技术《二》
Introduction to polyfit software
The 300th weekly match of leetcode (20220703)
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 framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
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
The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology
Online text line fixed length fill tool
Shell programming core technology II
英特尔集成光电研究最新进展推动共封装光学和光互连技术进步
How test engineers "attack the city" (Part 2)
The kth largest element in the array
2021 合肥市信息学竞赛小学组
Jetpack Compose 教程
在线文本行固定长度填充工具
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading