XML Parsing

Posted by LegacyUser on 02-Mar-2005 18:48

I am new to using progress to handle XML files, essentially what i need is pointing in the right direction with regards to how, once i read in an XML file using the CREATE X-DOCUMENT and LOAD() methods,do i search the document for data stored in Particular elements.

eg.

if the XML document contained the following elements

how would i search the document to return for example the contents of the Forename element.

Any help would be much appreciated.

Kinds Regards

Craig Hanson

Westland Payroll Services

Chris.Gray@proftech.co.uk

All Replies

Posted by Matt Baker on 04-Mar-2005 12:55

Use something like this...its pseudo code. You'll need more than just this.

xmldoc:document-root(root).

define variable i as integer no-undo.

do i = 1 to root:num-children:

hfornode = root:get-child(i).

if hfornode:name = "fornode" then do:

//something here

end.

end.

The other alternative is to use the sax reader which is faster since it does not load the xml doc into memory, but at the moment only allows reading an xml doc.

There are samples psdn.progress.com on how to read XML.

http://psdn.progress.com/cgi-bin/codeshare.cgi/search_results.w?subcategory=1

Posted by Admin on 23-Apr-2010 13:33

I got a question:

i have already seen how to write an XML document using SAX, let's create a simple XML file ->

DEFINE VARIABLE hSaxW AS HANDLE NO-UNDO.
CREATE SAX-WRITER hSaxW NO-ERROR.

hSaxW:SET-OUTPUT-DESTINATION("FILE","saxValidation.xml").
hSaxW:START-DOCUMENT().

hSaxW:START-ELEMENT("AddressMain").
hSaxW:START-ELEMENT("Address").

    hSaxW:START-ELEMENT("Address1").
    hSaxW:WRITE-CHARACTERS("MI direccion").
    hSaxW:END-ELEMENT("Address1").

    hSaxW:START-ELEMENT("City").
    hSaxW:WRITE-CHARACTERS("Mi Ciudad").
    hSaxW:END-ELEMENT("City").
   
    hSaxW:START-ELEMENT("State").
    hSaxW:WRITE-CHARACTERS("Mi Estado").
    hSaxW:END-ELEMENT("State").
   
    hSaxW:START-ELEMENT("Zip").
    hSaxW:WRITE-CHARACTERS("45079").
    hSaxW:END-ELEMENT("Zip").

hSaxW:END-ELEMENT("Address").
hSaxW:END-ELEMENT("AddressMain").
hSaxW:END-DOCUMENT().




This code generates the next XML file ->



 

    MI direccion
    Mi Ciudad
    Mi Estado
    45079
 


Once the file has been generated properly, i want to read it using SAX o DOM but i don't know how to READ it, could someone explain me how to read this file using SAX, DOM or both?

Thank's in advance!

Regards!

This thread is closed