1

How to make XPath list for a XML Message ?

Thanks for responding to my threads and looking into this issue. I have wellformed XML message. I want to produce a list/report as

1) All Xpath of XML message

2) Xpath , data content for this XPATH

Here is an example

<?xml version="1.0"?>
<PARTS>
   <TITLE>Computer Parts</TITLE>
   <PART>
      <ITEM>Motherboard</ITEM>
      <MANUFACTURER>ASUS</MANUFACTURER>
      <MODEL>P3B-F</MODEL>
      <COST> 123.00</COST>
   </PART>
   <PART>
      <ITEM>Video Card</ITEM>
      <MANUFACTURER>ATI</MANUFACTURER>
      <MODEL>All-in-Wonder Pro</MODEL>
      <COST> 160.00</COST>
   </PART>
   <PART>
      <ITEM>Sound Card</ITEM>
      <MANUFACTURER>Creative Labs</MANUFACTURER>
      <MODEL>Sound Blaster Live</MODEL>
      <COST> 80.00</COST>
   </PART>
   <PART>
      <ITEM>inch Monitor</ITEM>
      <MANUFACTURER>LG Electronics</MANUFACTURER>
      <MODEL> 995E</MODEL>
      <COST> 290.00</COST>
   </PART>
</PARTS>

I created the XML list manually

    /PARTS/TITLE                         Computer Parts
    /PARTS/PART[1]/ITEM                  Motherboard
    /PARTS/PART[1]/MANUFACTURER          ASUS
    /PARTS/PART[1]/MODEL                 P3B-F
    /PARTS/PART[1]/COST                  123.00
    /PARTS/PART[2]/ITEM                  Video Card
    /PARTS/PART[2]/MANUFACTURER          ATI
............
..............
..................
...................

I have XMLSPY, and I do not have additional tools kit associated with XMLSPY.

I tried with xml_grep in linux. It need the XPATH as input to get me the data content. I am not able to use xml_grep to extract attributes of XML message.

What are the ways to extract XPATHs/XPATH, data content?

Thanks for helping.

0

1 Answer 1

0

Here's my answer to my similar question :p

echo -e "setrootns\ncd defaultns:beans\ndir *" | xmllint --shell applicationContext.xml | grep -v -E ' TEXT| content=' | gawk 'BEGIN{ RS="ELEMENT "; FS=" *\n"} { print "/beans/" $1 "/@" $2 }' | sed -re 's/ +ATTRIBUTE // | uniq'
/beans// > setrootns/@/ > cd defaultns:beans
/beans/jaxrs:server/@id
/beans/bean/@id
/beans/import/@resource

The echo command "pipes" the followinf xmllint shell commands

# tell xmllint this xml has namespace declarations (not your case)
setrootns
# move to the first root node (PARTS in your case)
cd defaultns:beans
# list node contents
dir *

Result:

/ > setrootns
/ > cd defaultns:beans
beans > dir *
ELEMENT jaxrs:server
  ATTRIBUTE id
    TEXT
      content=CreateSurveyService
  ATTRIBUTE address
    TEXT
      content=/services
ELEMENT bean
  ATTRIBUTE id
    TEXT
      content=routingDataSource
  ATTRIBUTE class
    TEXT
      content=com.lsr.usc.datasource.routing.RegionCod...

The rest of the commands are used to parse this output.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .