XQL blues

Happy new year to everybody!

Now, My xml-newbie question is…

Why is this …

"xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns=“http://www.opentravel.org/OTA/2003/05” xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/

Stopping Xql from returning any results from my queries ?

After trial and error, I noticed that those lines are causing trouble… If I delete them everythin’s fine… Why ? and how do I overcome it ?


Sounds like badly formed SQL.
Where are the element fields?

That should be inside



The XML you need to parse will probably live in the Body element

<soap:Body> <m:GetPrice xmlns:m="http://www.w3schools.com/prices"> <m:Item>Apples</m:Item> </m:GetPrice> </soap:Body>

Hey Jeff… Not sure I understood you…
Yes, the XML data I need is inside the Soap Body Tag, but XQL fails to find anything because of the

<OTA_HotelResNotifRQ xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance
xmlns:xsd=“http://www.w3.org/2001/XMLSchema” Version=“0” xmlns=“http://www.opentravel.org/OTA/2003/05”>…

Here’s the first fragment of the long XML…

<?xml version="1.0" encoding="UTF-8"?>

<soap:Envelope xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/”>

<OTA_HotelResNotifRQ xmlns=“http://www.opentravel.org/OTA/2003/05” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” Version=“0”>

The namespace declaration in OTA_HotelResNotifRQ is causing the issue… Is there any way to remove it ?

If you are sure its that, you could issue a

thewholestring =  replace(thewholestring , unwantedpart, "")

on the full string before you load it into an XMLDocument for the XQL part.

Don’t change the document.

Write the XQL in the right mode:

dim x as new xmlDocument

dim xq as XmlNodeList
dim soapBody as XmlNode=x.DocumentElement.Xql(“soap:Body”)

dim msg as xmlNode
msg = soapBody.Xql(“OTA:MessageAcknowledgementType”,array(“OTA”, “http://www.opentravel.org/OTA/2003/05”))

dim notif as xmlNode
notif = soapBody.Xql(“OTA:OTA_HotelResNotifRQ”,array(“OTA”, “http://www.opentravel.org/OTA/2003/05”))

you can create a map array:
dim map() as string=array(“OTA”, “http://www.opentravel.org/OTA/2003/05”)

and reuse it in the XLQ
msg = soapBody.Xql(“OTA:MessageAcknowledgementType”,map)

in the notif you can “navigate” using firstChild and so on… or XQL with the map

Cool. I’ll make some tests and let you know how it goes

Sorry Antonio your code is not working for me…

dim xq as XmlNodeList // What is ‘Xq’ it doesn’t seem to be used at all ?

Dim soapBody as XmlNode=x.DocumentElement.Xql(“soap:Body”) // Should not soapboday be dimed as xmlnodelist ?

dim msg as xmlNode // Should it not be nodelist ?

Anyway… I couldn’t make it work… thanks anyway

it should be:
if xq.length>0 then dim soapBody as XmlNode=xq.item(0)

and so on

and it works… I always test a reply before writing it. Then as this time a I can write too quickly and skip something :slight_smile:

Hey Antonio… I am really stuck with this long XML… I need to make a nodelist with “hotelReservation” tags and I can not make XQL.(“HotelReservation”) query work… I even tried it in an online path tester and didn’t work… So I am starting to believe it is badly formatted as Jeff suggested… But I want to be sure before contacting the creator of the XML…

The intresting thing is if I delete the NS declaration in the OTA_HotelResNotifRQ parent tag… then magically the XQL query works
Can anyone take a look at it and help me ?

here’s the problematic stuff…


thanks a lot…

Try pasting it into here:


It seemms to be happy enough with it.
There are

6 HotelReservation nodes inside
1 hotelreservations inside
1 ota_hotelresnotifrq inside
1 soap:body

So you might try using XQL to get the one and only soap:body as a node.
Then XQL or iteration through a few children to get the ota_hotelresnotifrq node
Then it has one child, which is hotelreservations
And that has 6 nodes which are the ones you want.

Ok is not difficult. It’s only a matter of doing in the right order:

Say you have you XML document in xDoc

dim xDoc as xmlDocument xDoc.loadXML(theSource)

We will use XQL so let’s define a proper variable

dim xq as XmlNodeList

Now identify the body (soap:body) of this document:

dim soapBodyNode as xmlNode xq=xDoc.DocumentElement.Xql("soap:Body") if xq.length>0 then soapBodyNode=xq.item(0)

If there is no soapBodyNode we have finished.

Now all the nodes within the body have the name space relative to the service, so we have to define it, since it’s not defined in the document element and since it has no name we have to define one otherwise it will impossible to reach them:

dim otaNS() as string=array("OTA", "http://www.opentravel.org/OTA/2003/05")

Now we can find all the HotelReservation:

xq= soapBodyNode.Xql("OTA:OTA_HotelResNotifRQ/OTA:HotelReservations/OTA:HotelReservation", otaNS)

If xq.length>0 then you have the reservation that you have to analyze otherwise you have finished

dim n as integer=xq.length-1 for i as integer=0 to n AnalyzeReservation(xq.item(i), otaNS) next

Where AnalyzeReservation is your function (you have to define and work with it) that takes 2 parameter theReservationNode as XMLnode and ns() as string, that’s the service namespace.
Using firstChild, nextSbling or XQL you can read the information relative to the Reservation (most are as attribute)

You should have a documentation about it.

Jeff, Antonio thanks soo much for your help… It seems to be working now… This is my first time trying to parse an xml and I am just learning how to do it… really appreciate it… :slight_smile: