Join wMUsers | Blog at wMUsers | User Control Panel | Site Map | webMethods Jobs |For Employers

Haithem Al-Salam -- webMethods Ezine Columnist

Using Query Languages as Mapping Tools



By Haithem Al-Salam

 

Introduction

Mapping data from deeply hierarchical data structures is a challenging and time-consuming task for webMethods developers. The underused and powerful pub.web:queryDocument service can drastically simplify this process.

Allowing the developer to use the XQL and WQL query languages on webMethods Records, pub.web:queryDocument extracts data directly from the source document.

Query language syntax is based on a basic URI syntax best illustrated by example.

This webMethods Ezine article uses XQL in its examples, but beyond the syntax differences of the two languages, the two options offer similar functionality.


Sample XML Document

The XML document is the basis for all XQL queries in the article:

<Transaction>
  <Header>
    <Party role="Buyer">
      <Code type="DUNS">123456789</Code>
      <Name>CompanyX</Name>
      <Contact>
        <Name>Sam the Buyer</Name>
        <Address>
          <Street>555 Bill Ave</Street>
          <City>Dallas</City>
          <State>Texas</State>
          <Country>USA</Country>
        </Address>
        <PhoneNumber>555-555-4444</PhoneNumber>
      </Contact>
    </Party>
    <Party role="Seller">
      <Code type="DUNS">456789123</Code>
      <Name>CompanyY</Name>
      <Contact>
        <Name>Jill the Seller</Name>
        <Address>
          <Street>12343 Joe Street</Street>
          <City>Seattle</City>
          <State>Washington</State>
          <Country>USA</Country>
        </Address>
        <PhoneNumber>555-555-5555</PhoneNumber>
      </Contact>
    </Party>
    <SubmitDate>01-01-2003</SubmitDate>
  </Header>
  <Details>
    <Item number="1">
      <IDNumber>11111</IDNumber>
      <Amount>100.11</Amount>
      <Account>10001</Account>
      <ServiceDate>01-12-2002</ServiceDate>
    </Item>
    <Item number="2">
      <IDNumber>22222</IDNumber>
      <Amount>200.22</Amount>
      <Account>20002</Account>
      <ServiceDate>02-12-2002</ServiceDate>
    </Item>
    <Item number="3">
      <IDNumber>33333</IDNumber>
      <Amount>300.33</Amount>
      <Account>30003</Account>
      <ServiceDate>03-12-2002</ServiceDate>
    </Item>
    <Item number="4">
      <IDNumber>44444</IDNumber>
      <Amount>400.44</Amount>
      <Account>40004</Account>
      <ServiceDate>04-12-2002</ServiceDate>
    </Item>
  </Details>
</Transaction>


Basic XQL syntax

As mentioned earlier, the easiest way to explain query language is by example so let's look at the return values of some XQL queries on the XML document described above.

XQL QueryResults
/Transaction/HeaderAll Header elements that are children of the root element Transaction
//HeaderAll Header elements anywhere within the document
/Transaction/*All child elements of the root element Transaction
/Transaction/*/ItemAll Item records that are grand-children of the root element Transaction
//Item/AccountAll Accounts that are children of any Item element within the document
//Details/Item[0]The first Item element that that is a direct child of any Detail tag
//Details/Item[0]/@numberThe value of the attribute "number" for the first Item child element of any Details tags

 

To narrow results, there are common operators that can be applied to the query statement. Conditions are expressed inside of brackets ("[" and "]") and the operators "=", "!=", "<", ">" can be used for comparisons.

XQL QueryResults
//Item[@number="5"]All Item record where the number attribute = 5
//Item[@number="5"]/IDNumber/TD>All IDNumbers that are children of any Item tags that have the attribute "number" equal to "5".

 

The above examples, by no means, cover the full range of features supported by XQL. Please refer to the ISDeveloperGuide.pdf for a complete coverage XQL and WQL features.


Flow development using pub.web:queryDocument

In using pub.web:queryDocument and its supported query languages, a developer must understand a few webMethods-specific nuances for extracting the desired data and mapping it to the desired structure.

First, one can think of pub.web:queryDocument as binding the result of the query to an output Record. The output Record can be an arbitrarily complex structure.

Second, each level of the output Record is bound to the return of a specific source data query. Each child element of the output Record can be bound to a query that is expressed relative to its parent. This is a very powerful feature results in concise and legible code.

Third, if the output Record does not explicitly declare its child elements down to a string-oriented variable (such as a String or String List),the output Record is instead returned as a node object.

To see pub.web:queryDocument in action, see these seven screen shots from an invocation.



[1]  2  Next>>

Go Deeper on the Subject: The wMUsers Discussion Forums


Haithem Al-Salam is 4-year veteran of software development with a heavy focus on Business Integration. He is currently working for Digital Oilfield, implementing Business-to-Business integrations for the Oil and Gas sector including PIDX invoicing.

Haithem can be reached via email at .


Advertise at wMUsers






  Home | Join wMUsers | Discussion Forums | Knowledge Center | Jobs | Shareware | User Groups | Links |
Contact Us | Terms of Service | Privacy Policy

wMUsers is an independent organization and is not sponsored in any manner by Software AG.


© All Rights Reserved, 2001-2008.