When using the old stream classes (%Library.GlobalXXXXStream) you should never set a stream property A to the oref from another stream B, as the Location value of stream B will be copied into stream A. You should use CopyFrom to avoid this Location change.

Taking @Lorenzo Scalese  sample method add2(), it should be rewriiten as:

ClassMethod add2() As %Status
{
   Set = ..%New()
   Set st = ##class(%GlobalBinaryStream).%New()
   Do st.Write("azeruiop")
   //Set o.st = st
   Do o.st.CopyFrom(st)
   Quit o.%Save()
}
 

If you use the new stream classes %Stream,GlobalXXXX, the original code from method add2() will keep the Location from stream property:

ClassMethod add2() As %Status
{
Set = ..%New()
Set st = ##class(%Stream.GlobalBinary).%New()
Do st.Write("azeruiop")
Set o.st = st
Quit o.%Save()
}

 

It's not a pretty solution but you can achieve it using a terminal script (iristerm/cterm). The script will call your routine and when it ends it will throw a popup alert informing that your routine did finish. It will not bring the terminal to the foregroung but you get the alert.

Save this to a file:

send: d ^myRoutine<cr>
wait for: USER>
execute: mshta vbscript:Execute("msgbox ""Routine myRoutine finished processing."",48:close")

In terminal, press ALT+S and select the your script file and when the routine ends you will see a popup.
 

The code below does want you want.

    While textreader.Read() {
        If textreader.NodeType = "element"  {  
            Set elementName=textreader.Name  
        }
        ElseIf textreader.NodeType = "chars" {
            Set elementValue=textreader.Value
            Set practices=practices_elementName_":"_elementValue_" "
        }
    }
    Write practices
 

Hi Francisco,

I've downloaded the latest version 1.1.1 to add Portuguese-Brazil (pt-br) and Portuguese (pt) from Portugal, there are some differences as in Brazil shortscale notation is used while in Portugal they use longscale notation. There are also slightspelling differences.

The first problem I encountered with versions 1.1 and 1.1.1 was that both were exported from IRIS and Caché currently does not recognize the <Export generator="IRIS" ...> tag and fails to import the file. Editing the XML file and changing IRIS by CACHE solved the import issue.

It would be nice to have the XML exported as Caché so everyone will be able to import it.

There is an issue with some numbers like 12345 that returns an <INVALID OREF> because the OREF "obj" was killed. Large numbers in the trillion range return wrong results like 123456789123456.

I have these issues fixed and have also added the code for Portuguese (pt-br and pt). I'll send the changed classe to you for analysis.

Best Regards,

Ernesto


Hi Yuriy,

Currently there are no API's to convert XML to JSON but it can be done quite easily in different ways.

One approach you can use is if your XML has always the same structure, you can create a class(es) in HS that corresponds to this XML structure. With this class(es) you can now use %XML.Reader and method Correlate() to load the XML into the class(es). Here you can find more information about this:
http://docs.intersystems.com/ens20162/csp/docbook/DocBook.UI.Page.cls?KEY=GXML_import

After correlating the XML to your class you should then use method %WriteJSONStreamFromObject from class %ZEN.Auxiliary.jsonProvider to dump this object in JSON format into a stream. Documentation is here:
http://docs.intersystems.com/ens20162/csp/documatic/%25CSP.Documatic.cls?PAGE=CLASS&LIBRARY=%25SYS&CLASSNAME=%25ZEN.Auxiliary.jsonProvider#%WriteJSONStreamFromObject
There is also a string version of this method but your JSON will need to fit in up to 3.5MB.

This is the simplest approach but it relies on being able to represent your XMLs as a class (or classes) in HS.

Another approach is to use some external third-party library to convert XML to JSON. There are several open source libraries for Java, .Net, Python, and others.

I have my Windows configuredwith keyboard as "US International", this makes it very easy to get quite all of these accented and special letters.

I just type a single quote ' folowed by an e and get é. This is very usefull if you need to write in languages that have accented characters like all latin ones.

Of course there are some cons, like if I want a single quote I need to type ' followed by a space so I get it on screen and it does not get combined with another letter that can have accent variations.

So, which one should I use? Every newbie would ask.

In terms of readability I like the FOR structure as it is the cleanest one, very easy to view. Both WHILE and DO WHILE are also great but after being rewritten as John Hotalen showed.

Another newbie's question would be: Is there any performance difference?

So I did some simple performance tests with all these traversing methods including a $Query one and working with this same ^Trans global but now populated with 50 million nodes. They all have very similar performance with exception of the FOR DO DOT syntax and $Query (uses indirection) that are much slower (~10%).