User bio
404 bio not found
Member since Jul 25, 2017
Replies:

If your system does not support JSON (i.e. pre 2016.2?) then give this "dirty trick" a try:

- add a zero-width-space character to your numbers
- create the output stream
- remove the zero-width-space characters

Instead of the zero-width-space you can use any other character too, which does not appear in your data (binary data should be base64 encoded).

ClassMethod WithQuotes()
{
	set zwsp = $c(8203) // zero-width-space
	set obj = ##class(%ZEN.proxyObject).%New()
	
	set obj.ID = 1234_zwsp
	set obj.Number=123.45_zwsp
	
	if ##class(%ZEN.Auxiliary.jsonArrayProvider).%WriteJSONStreamFromObject(.tmp,obj) {
  		set json=##class(%Stream.TmpBinary).%New()
		do tmp.Rewind()
		while 'tmp.AtEnd { do json.Write($tr(tmp.Read(32000),zwsp)) }
	}
	
	do json.Rewind()
	write json.Read(json.Size)
}

The one way is to use %XML.TextReader

ClassMethod Reader(str, pth, ByRef val)
{
	kill val
	set val=0
	// Adjust the method name below to your needs
	// ParseString(), ParseStream(), ParseFile() 
	if ##class(%XML.TextReader).ParseString(str,.rdr) {
		while rdr.Read() {
			if rdr.NodeType="chars",rdr.Path=pth set val($i(val))=rdr.Value
		}
		quit 1
	}
	quit 0
}

set str="<?xml version=""1.0"" encoding=""UTF-8""?><Input><data><Ids><Id><Type>A</Type><Value>123</Value></Id><Id><Type>B</Type><Value>456</Value></Id></Ids></data></Input>"
write ##class(yourClass).Reader(str,"/Input/data/Ids/Id/Value",.val) --> 1
zw val -->
val=2
val(1)=123
val(2)=456

The other way is to use %XML.Reader() and correlate to a class which describes your XML structure

Certifications & Credly badges:
Julius has no Certifications & Credly badges yet.
Global Masters badges:
Followers:
Following:
Julius has not followed anybody yet.