How to export class to xml without namespace?

278 Views Asked by At

I am using IRIS (Intersystems) and trying to export a class to xml and remove the tag "xmlns" from mother class. These are my classes to create the XML.

Class Test:

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

Class Person:

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

Class Address:

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

That is my function to export the 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()

This is the xml that was generated:

<?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>

When i delete the Parameter NAMESPACE from Class.Test this happens with my 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>

Someone can help me? I want to create this 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>

Best Regards.

1

There are 1 best solutions below

0
On

You already extend %XML.Adaptor in your class, so, you may directly export the object

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

Will outputs

<Test><Person><name>John</name><age>22</age></Person><Address><location>New York NY 10036</location></Address></Test>