%XML.Document adding nodes

149 views
Skip to first unread message

Klimaks

unread,
Jan 4, 2011, 4:25:53 PM1/4/11
to Caché, Ensemble, DeepSee
Hello,

I'm trying to create an XML document with %XML.Document class. With
the following code I can create a basic xml file. But I'm unable to
add some nodes to the file. I've tried using AppendChild or
AppendElement but none of that seems to work. Does someone has an
example of how to use this class. (I need to make a Excel xml fle).

S doc=##class(%XML.Document).CreateDocument("document")
//d doc.AppendChild("test")
//d doc.InsertCharacter("txt","test")

set writer=##class(%XML.Writer).%New()
set writer.Charset="UTF-8"
//set sc=writer.OutputToString()
set sc=writer.Document(doc)
s xml=writer.GetXMLString()

rtweed

unread,
Jan 5, 2011, 3:00:03 AM1/5/11
to Caché, Ensemble, DeepSee
You might find EWD's lightweight XML DOM APIs easier to deal with -
see my other posting here and
https://groups.google.com/group/enterprise-web-developer-community/browse_thread/thread/36c7503939bbc460/3930b573c5726fd0?hl=en&lnk=gst&q=xml+dom#3930b573c5726fd0

You'll be able to use it to do everything you're wanting to do with
Excel.

Rob

Klimaks

unread,
Jan 5, 2011, 4:55:52 AM1/5/11
to Caché, Ensemble, DeepSee
Sounds interesting. Is the documentation that is included in the
EWDmgr application available online? So I can check it out before
installing all kind of things on our server.



On Jan 5, 9:00 am, rtweed <rob.tw...@gmail.com> wrote:
> You might find EWD's lightweight XML DOM APIs easier to deal with -
> see my other posting here andhttps://groups.google.com/group/enterprise-web-developer-community/br...

servit

unread,
Jan 5, 2011, 7:03:20 AM1/5/11
to Caché, Ensemble, DeepSee
Hello, Klimaks.

You can try library to generate Excel XML (base functional, the
author: Блок А.Н.): http://www.sql.ru/forum/actualthread.aspx?bid=56&tid=814407
Excel.rar: http://www.sql.ru/forum/actualfile.aspx?id=9946539

Call from the Caché Terminal:
USER>do ##class(Excel.Document).Test()

PS: the code of classes contains the text and comments in Russian.
Sorry...
PPS: there is a similar library, but for the Word XML.

rtweed

unread,
Jan 5, 2011, 10:20:12 AM1/5/11
to Caché, Ensemble, DeepSee
I'm afraid not, but if you're familiar with the standard XML DOM API
then that's pretty much what it provides you with, in addition to all
sorts of macro commands that do useful stuff like adding a complete
tag, removing an intermediate tag, inserting a new tag between a
parent and its child tags etc etc.

Quickest way to see it all without affecting your existing server(s)
is to use the M/DB installer with a Ubuntu Linux VM (or Amazon EC2 VM)
- you'll have a fully working EWD system up and running in a few mins
and be able to access the entire documentation. Details on our web
site

Rob

Klimaks

unread,
Jan 5, 2011, 2:13:37 PM1/5/11
to Caché, Ensemble, DeepSee
Seems like a fine solution, but sadly enough it doesn't work. It only
creates zerobytes file. Any clue what that could be?

servit

unread,
Jan 6, 2011, 1:06:56 AM1/6/11
to Caché, Ensemble, DeepSee
Hello, Klimaks.

I think it's because of the encoding of file.
Try to set the default locale "rusw" (for Caché Unicode) or
"rus8" (for Caché 8-bit).

Klimaks

unread,
Jan 6, 2011, 4:57:13 AM1/6/11
to Caché, Ensemble, DeepSee
Hello,

Thanks for your help. I've got it all working now.

Fabian Haupt

unread,
Jan 6, 2011, 5:06:45 AM1/6/11
to intersystems...@googlegroups.com
There's no need to used external software,
you can use %XML.Node for that. Have a look at
http://docs.intersystems.com/cache20102/csp/docbook/DocBook.UI.Page.cls?KEY=GXML_dom

It explains everything you need.

Klimaks

unread,
Jan 7, 2011, 7:22:57 AM1/7/11
to Caché, Ensemble, DeepSee
Hello,

We succesfully managed to make Excel-xml files with the link you
provided.
Now we are trying to read the files back to Caché objects.
But when I try to read a file it gives the following error :

Key attribute not specified for an array tag: Style

but the XMLKEYNAME paramter is set on the array of Styles, so i
believe it should be working

any thoughts on this?

servit

unread,
Jan 7, 2011, 8:21:31 AM1/7/11
to Caché, Ensemble, DeepSee
Hello, Klimaks.

The library was not originally designed to read, only to generate the
file.
Reply all
Reply to author
Forward
0 new messages