• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using XPath to read list of nodes

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all. I'm trying to use XPath expressions to read an XML file. My basic question is, how do I create a method that uses XPath to position a 'pointer' to a section within an XML document, then iterate through 'child' and 'grandchild' nodes looking for desired values?
Here is the relevant subset of the file:

I wrote (actually, copied from somewhere, probably the Moose) a little helper method to look for data elements within the XML:

..and I use the method like this:

Everything works pretty well if the section I'm looking for occurs only once in the file. But I want to access the attributes FONTFACE, FONTSIZE, XPOS, YPOS and TEXT within each MESSAGE section. I suppose could rename the MESSAGE nodes to MESSAGE1, MESSAGE2, MESSAGE3, then path them in explicitly, but I'd prefer to leave it flexible enough that I could add a fourth MESSAGE.
I realize that I couldn't return all five child elements at once. But I figured I'd create another class with member variables for each element and use that for the return value.
Thanks in advance for any help,
Rick <><
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Iam not sure what u are trying to get but from my understanding of u'r question try this
//MESSAGES/TEXT[contains(.,"SEE ATTACHED")
This returns the "whole" of the first Message Node
Hari
 
Rick Crawford
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hari,
Thanks for the reply. One thing that I didn't make very clear is that FONTFACE, FONTSIZE, XPOS, etc. are nodes that are common for several data items that are not shown in my example, not just the MESSAGES nodes. The entire XML configuration file is pretty big, but here are a few more nodes in addition to the MESSAGES section:

What I'd like to do is access this data by the high level node name, such as SHIPPERNAME, then pick out these common fields and store them in a structure (an inner class.) Right now, I'm retrieving the values with multiple calls to my 'getVal' method, like this:

..and so on. But what I'd rather do is create some sort of a method call that would interrogate all the nodes within the '/MAINPAGEOVERLAY/SHIPPERNAME', looking for the named values of FONTFACE, FONTSIZE, etc., storing them within a structure:

My imaginary method signature (that I can't figure out how to write):

I would then use the values from the returned printPosition object. And as I alluded to in the previous message, the high level node, such as MESSAGES, could contain lower level nodes such as MESSAGE. But at some point when the lowest level has been reached, the common attributes of FONT and XPOS would be found.
This is all pretty complicated, and I apologize if I'm not being very clear on this. As always, I sincerely appreciate the help.
Rick <><
 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic