0

我正在使用 IRIS(Intersystems)并尝试将类导出到 xml 并从母类中删除标签“xmlns”。这些是我创建 XML 的类。

班级测试:

Class Class.Test Extends (%RegisteredObject, %XML.Adaptor)
{ 
Parameter NAMESPACE = "http://mynamespace.com/test"; 
Property Person As Class.Person; Property Address As Class.Address; 
}

班级人:

Class Class.Person Extends (%RegisteredObject, %XML.Adaptor)
{ 
Parameter NAMESPACE = "http://mynamespace.com/test"; 
Property name As %String; Property age As %String; 
}

上课地址:

Class Class.Address Extends (%RegisteredObject, %XML.Adaptor)
{ 
Parameter NAMESPACE = "http://mynamespace.com/test"; 
Property location As %String; 
}

这是我导出 XML 的功能:

set writer=##class(%XML.Writer).%New()
set writer.Indent=1
set writer.Charset="ISO-8859-1"
set status=writer.OutputToString()
set status=writer.RootObject(objectTest)
set xml=writer.GetXMLString()

这是生成的xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Test xmlns="http://mynamespace.com/test">
<Person>
    <name>John</name>
    <age>22</age>
</Person>
<Address>
    <location>New York NY 10036</location>
</Address>
</Test>

当我从 Class.Test 中删除参数 NAMESPACE 时,我的 xml 会发生这种情况。

<?xml version="1.0" encoding="ISO-8859-1"?>
<Test>
<Person xmlns:s01="http://mynamespace.com/test">
    <s01:name>1</s01:name>
</Person>
<ResultadoCultura xmlns:s01="http://mynamespace.com/test">
    <s01:location>New York NY 10036</s01:location>
</ResultadoCultura>
</Test>

有人可以帮助我吗?我想创建这个 XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Test>
<Person>
    <name>John</name>
    <age>22</age>
</Person>
<Address>
    <location>New York NY 10036</location>
</Address>
</Test>

此致。

4

1 回答 1

0

您已经在类中进行了扩展%XML.Adaptor,因此,您可以直接导出对象

  Set status = objectTest.XMLExportToString(.xml)
  Write xml

将输出

<Test><Person><name>John</name><age>22</age></Person><Address><location>New York NY 10036</location></Address></Test>
于 2021-10-16T00:07:00.700 回答