XML string to Serial Object
Hello.
I want to know how can I convert XML String intro a %SerialObject.
This is an example:
<Envelope>
<Body>
<RESULT>
<SUCCESS>TRUE</SUCCESS>
<LIST>
<ID>11111</ID>
<NAME>one</NAME>
</LIST>
<LIST>
<ID>22222</ID>
<NAME>two</NAME>
</LIST>
</RESULT>
</Body>
</Envelope>
<Body>
<RESULT>
<SUCCESS>TRUE</SUCCESS>
<LIST>
<ID>11111</ID>
<NAME>one</NAME>
</LIST>
<LIST>
<ID>22222</ID>
<NAME>two</NAME>
</LIST>
</RESULT>
</Body>
</Envelope>
And this are the %SerialObject classes I have created:
Class test.Envelope Extends (%SerialObject,%XML.Adaptor)
{
Property Body As test.Body;
}
{
Property Body As test.Body;
}
Class test.Body Extends (%SerialObject,%XML.Adaptor)
{
Property RESULT As test.Result;
}
{
Property RESULT As test.Result;
}
Class test.Result Extends (%SerialObject,%XML.Adaptor)
{
Property SUCCESS As %String(MAXLEN = "");
Property LIST As list Of test.List;
}
{
Property SUCCESS As %String(MAXLEN = "");
Property LIST As list Of test.List;
}
Class test.List Extends (%SerialObject,%XML.Adaptor)
{
Property ID As %String(MAXLEN = "");
Property NAME As %String(MAXLEN = "");
}
{
Property ID As %String(MAXLEN = "");
Property NAME As %String(MAXLEN = "");
}
I have tested with a function like this:
set reader = ##class(%XML.Reader).%New()
set sc = reader.OpenStream(xmlStream)
do reader.Rewind()
do reader.CorrelateRoot("test.Envelope")
while (reader.Next(.tMessage,.sc)) {
set OUT = tMessage
}
set sc = reader.OpenStream(xmlStream)
do reader.Rewind()
do reader.CorrelateRoot("test.Envelope")
while (reader.Next(.tMessage,.sc)) {
set OUT = tMessage
}
But it only works if property "LIST" is a single object and not a list of objects. When I try with the list, I get this error:
ERROR #6237: Unexpected tag in XML input: LIST (ending at line 6 character 5).
How can I convert a XML String into a SerialObject?
Thank you in advance.