Question
· Aug 31, 2020

How to accept / as a valid character when parsing XML

I'm trying to parse some XML but I ran into an issue where my data has a / in it (see below).

<pArray index="0">/shared/BENANDERSON</pArray>

When I ran it, I got this error.

ERROR #6232: Datatype validation failed for tag, pArray (ending at line 1 character 183), with value: /shared/BENANDERSON

Here is the code where I found the issue occurring. The XML reader must see the / as the invalid character. The value of P0 eventually ends up as null which causes another issue downstream. Is there a way for me to proceed with the / in the data? Thank you!

do %request.Content.Rewind()
set content = %request.Content.Read($$$MaxStringLength)
Set reader = ##class(%XML.Reader).%New()

Set status = reader.OpenString(content)

Do reader.Correlate("visMExecuteResult","ExecuteResult")

Do reader.Next(.executeResult,.status)
    }
else
{
return ..HttpException415("Only json or xml is allowed", "Execute")
}

set currentNamespace = $NameSpace
set NameSpace = executeResult.NameSpace

set Code = executeResult.Code
set Error = executeResult.Error

set ErrorName = executeResult.ErrorName

set PArray = executeResult.PArray
set P0 = executeResult.PArray.GetAt(0)

Discussion (5)0
Log in or sign up to continue

make sure your / is really just a / and not surrounded by some nonprinting stuff
do a check e.g on https://www.xmlvalidation.com/ 

(ending at line 1 character 183)  could also mean you are missing
<?xml version="1.0" encoding="UTF-8"?>  as first line.

next possible trap: your xml is not encode in UTF-8  (but in some other [windows?]
code after modification with Notepad.exe or similar.

You're getting a "Datatype validation" error, which suggests that the XML parsed fine, but that the value "/shared/BENANDERSON" is not valid for the PArray property of the ExecuteResult class.

If PArray is an array, I don't remember how that's typically projected to XML, and I can't find an example in the documentation. Lists are projected as a container element with the contents nested as elements within. Are you reading in something that was written using an %XML.Writer, or are you designing a class to read an XML file from somewhere else?

It might help to see more context in the XML, and the relevant definitions from the ExecuteResult class.