XML Parser

israelm

New Member
Hi there, i would like to know if it's possible to read an XML file using WebSpeed:
For example, how to read and get the values of next file?

I Guess webSpeed must have an XML Parser, anyone have more information about the XML parser?

HTML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<CATALOG>
    <CD>
        <TITLE>Empire Burlesque</TITLE>
        <ARTIST>Bob Dylan</ARTIST>
        <COUNTRY>USA</COUNTRY>
        <COMPANY>Columbia</COMPANY>
        <PRICE>10.90</PRICE>
        <YEAR>1985</YEAR>
    </CD>
    <CD>
        <TITLE>Hide your heart</TITLE>
        <ARTIST>Bonnie Tyler</ARTIST>
        <COUNTRY>UK</COUNTRY>
        <COMPANY>CBS Records</COMPANY>
        <PRICE>9.90</PRICE>
        <YEAR>1988</YEAR>
    </CD>
    <CD>
        <TITLE>Greatest Hits</TITLE>
        <ARTIST>Dolly Parton</ARTIST>
        <COUNTRY>USA</COUNTRY>
        <COMPANY>RCA</COMPANY>
        <PRICE>9.90</PRICE>
        <YEAR>1982</YEAR>
 </CD>
</CATALOG>
Thanks in advance!
Israel M.|
 

RealHeavyDude

Well-Known Member
You don't say anything about your OpenEdge/WebSpeed version. This is essential information as the DOM as well as the SAX parser have been introduced into the ABL at different times. AFAIK, the SAX parser is not available before OE 10.0B.

In OE10 in the documentation there is a chapter "working with XML" which, IMHO, is exactly what you're looking for.

You can also lookup the documentation on the Progress home page. There you will also find a link to the Progress V9 documentation.

HTH, RealHeavyDude.
 

israelm

New Member
Thanks for the link with the samples.

Now,
I am using this testing API ->

http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=XMLrequest

Which gets me back this result ->

HTML:
<AddressValidateResponse>
<Address ID="0">
<Address2>6406 IVY LN</Address2>
<City>GREENBELT</City>
<State>MD</State>
<Zip5>20770</Zip5>
<Zip4>1440</Zip4>
</Address>
</AddressValidateResponse>
I need to read this XML file but result is still on http://testing.shippingapis.com/ShippingAPITest.dll, do you know how can i get the content of this file?
As far as i know php provides cURL module which make these kind of jobs easier, is there something similar for WebSpeed?.

Thank you.
 

RealHeavyDude

Well-Known Member
First of all, your OpenEdge version support both the DOM and SAX parser.

Regarding your question: Is this a WebService call or what is this? Don't know anything about cURL.

Regards, RealHeavyDude.
 

NormaLucia

New Member
Hi there, this is israelm.

My account got blocked since i tried to change my email account, that's why im asked a friend to use her progress talk account to continue with this discution. (I have already sent many requests to admin i have no received any response yet, even i tried to create a new account and i dont get the email to confirm my email address and activate the new account).

Thank you for responding HeavyDude, i have already researched about the OpenEdge SAX and DOM support for OpenEdge10.1A + and it's great!

You don't need to know anything about php cURL i was just taking it as reference.

Now i know how to read and write XML using SAX and DOM.

Im requesting an USPS (United States Postal Service) address validation, works like a webService, basically i send an XML request with the information i need to validate and i get an XML response from them, i just need to know how can i get the XML to read it if it is still on the USPS server?

The XML is contained on this link: http://testing.shippingapis.com/shippingAPITest.dll?API=Verify&XML=xmlIntruction

This URL get's back an XML result, wich is contained there, as you can see it's not an xml file, it is an .dll

Id like to try to read it with DOM, that would be something like:

Code:
DEF VAR hDoc AS HANDLE NO-UNDO.
DEF VAS hRoot AS HANDLE NO-UNDO.
 
CREATE X-DOCUMENT hDoc.
hDoc:LOAD("FILE","[URL]http://testing.shippingapis.com/shippingAPITest.dll?API=Verify&XML=xmlIntruction",FALSE[/URL]).
 
hDoc:GET-DOCUMENT-ELEMENT(hRoot).
 
(Etc... Continue reading the XML file)...

Is it posible? if not, how can i read that document?

I appreciate you help.

Best Regards
Israel M.
 

RealHeavyDude

Well-Known Member
AFAIK using a URL for a file load should work - though I have to admit that I didn't test it ...

If that does not work the only thing I can come up with right now is to post your request using socket programming and save the response (the XML document) either on a memory pointer or a file which you can use for the LOAD method.

HTH, RealHeavyDude.
 

NormaLucia

New Member
Cool, it can read across server properly. Now i can read the XML file using DOM, but is kind of complex trying to read it since i don't know all DOM commands for Open Edge.

This is the file im trying to read ->

HTML:
<?xml version="1.0"?>
<AddressMain>
  <Address>
    <Address1>MI direccion</Address1>
    <City>Mi Ciudad</City>
    <State>Mi Estado</State>
    <Zip>45079</Zip>
  </Address>
</AddressMain>
and this is the code to read it ->

Code:
DEFINE VARIABLE hDoc   AS HANDLE NO-UNDO.
DEFINE VARIABLE hRoot  AS HANDLE NO-UNDO.
DEFINE VARIABLE hChild AS HANDLE NO-UNDO.
DEFINE VARIABLE hChild1 AS HANDLE NO-UNDO.
DEFINE VARIABLE hText  AS HANDLE NO-UNDO.
DEFINE VARIABLE i      AS INT NO-UNDO.
DEFINE VARIABLE j      AS INT NO-UNDO.
DEFINE VARIABLE cID    AS CHAR NO-UNDO.
DEFINE VARIABLE cValue AS CHAR NO-UNDO.

/* Create document and node references */
CREATE X-DOCUMENT hDoc.
CREATE X-NODEREF hRoot. 
CREATE X-NODEREF hChild.
CREATE X-NODEREF hChild1.
CREATE X-NODEREF hText.

hDoc:LOAD("FILE","saxValidation.xml",FALSE).

hDoc:GET-DOCUMENT-ELEMENT (hRoot). 

DO i=1 TO hRoot:NUM-CHILDREN:
    
    hRoot:GET-CHILD(hChild,i). 
    IF hChild:NUM-CHILDREN < 1 THEN NEXT. 
    
    hChild:GET-CHILD(hChild1,1).
    
    DO j=1 TO INT(hChild1:NUM-CHILDREN):
        {&out} string(j) "<br />".
        IF hChild1:NUM-CHILDREN < 1 THEN NEXT.
        hChild1:GET-CHILD(hText, j).
        {&OUT} hText:NODE-VALUE.
        {&OUT} string(hChild:NUM-CHILDREN).
    END.
END.
I get this message: Content-type: text/html nX-NODEREF must be associated with a valid X-DOCUMENT in order to use it in method NUM-CHILDREN. (9102)

Would be amazing if someone could explain to me the correct way to read this file or tell me where can i get more information related to read XML files using DOM.

Best Regards!
Israel M,|
 

RealHeavyDude

Well-Known Member
To be honest - I never use the DOM model. Mostly because I was able to parse XML documents with the SAX-READER in a much more straightforward way then using DOM with all requirements to parse XML documents that came over my desk over the past years. The only limitation of the SAX-READER is that it's parsing the document sequentially ( there is no hopping around ), and, but that's not a limitation in my opinion, you need to maintain the context information yourself.

Did you consider using the SAX-READER instead of DOM?

But if you really want to use the DOM parser then you should have a look into the documentation which, AFAIK, also includes sample code for parsing XML using DOM.


Regards, RealHeavyDude.
 

NormaLucia

New Member
Well actually, doesn't matter if i use DOM or SAX, i choice DOM because seems easier to read XML than SAX, but i can use SAX-READER as well.
 

NormaLucia

New Member
Thank you for the tutorial, that was exactly what i was looking for.
I have solved my issue, now i can read across servers and interpret the message that i receive using DOM (Which is very easy to implement).

One question more, as i am sending the XML via HTTP GET as string i need to change my XML structure, Let me explain:

I need to change this symbols: < > " ' to %3C %3E %20 % 22

So my XML request should looks like ->
Code:
%3CAddressValidateRequest%20USERID=%22%22%3E%3CAddress%20ID=%220%22%3E%3CAddress1%3E%3C/Address1%3E%3CAddress2%3E6406%20Ivy%20Lane%3C/Address2%3E%3CCity%3EGreenbelt%3C/City%3E%3CState%3EMD%3C/State%3E%3CZip5%3E%3C/Zip5%3E%3CZip4%3E%3C/Zip4%3E%3C/Address%3E%3C/AddressValidateRequest%3E
Is there a WebSpeed Function that allow me to do this?
Otherwise i guess i would need to create my own.

Thanks!
Israel M,|
 

RealHeavyDude

Well-Known Member
AFAIK there are two methods URL-ENCODE() and URL-DECODE() which are used by the url-encode and url-decode WebSpeed API.

HTH, RealHeavyDude.
 

NormaLucia

New Member
Once again you're right.

The encode procedure needs a second parameter : URL-ENCODE(xml2url,'query').
I Found with 'query' works since i saw a sample in another post.

Regards!
 
Top