Question
· Oct 15, 2021

How to export class to xml without namespace

Hello everybody,

 

I am trying to export a class to xml and remove the tag "xmlns" from mother class. These are my classes to create the 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; 

}

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.

Discussion (1)1
Log in or sign up to continue