It would look like this:

/*/Data/Products/Product/@ProductId

Note that the document element has a namespace attached so if you assigned the 
namespace-uri "urn_someurl" to the prefix "pr" you could make that:

/pr:Feed/Data/Products/Product/@ProductId

The '@' specifies an attribute as opposed to an element.

-----Original Message-----
From: u2-users-boun...@listserver.u2ug.org 
[mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Bobby Worley
Sent: November-09-11 10:45 AM
To: U2 Users List
Subject: [U2] Extracting XML attributes

Does anyone have an example of an XPath definition to extract an attribute from 
an XML element?  The universe documentation for 10.3 and
11.1 doesn't cover this.

I am trying to get the value of "ProductId" from the following XML
example:

<pr:Feed xmlns:pr="urn:someurl">
  <Data>
    <Products>
      <Product ProductId="ABC">
          ...
      </Product>
      <Product ProductId="123">
          ...
      </Product>
      <Product ProductId="XYZ">
          ...
      </Product>
   </Products>
  </Data>
</pr>

Using the this extraction file:

<U2XML_extraction xmlns:USxml="http://www.rocketU2.com/U2-xml"; >
   <file_extraction start="/Data" dictionary="XMLTESTFILE" null="EMPTY"
/>
   <field_extraction field="@ID" path="Products/Product/@ProductId" ,/> 
</U2XML_extraction>

I get the following error:

>LIST XMLDATA EDGENET_XML "&XML&/test.ext"
Open XML data file failed.
XMLParser error message: Fatal error at file '/Volume1/MIS/&XML&/test.ext', 
line 3, column 69. Message: Expected an attribute name

Open XML data file failed.
XMLParser error message: Fatal error at file '/Volume1/MIS/&XML&/test.ext', 
line 3, column 69. Message: Expected an attribute name

Unable to open "XMLDATA:EDGENET_XML,&XML&/test.ext" file.
>
_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users
_______________________________________________
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to