Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > More information on REXML/XPath

Reply
Thread Tools

More information on REXML/XPath

 
 
Peter Bailey
Guest
Posts: n/a
 
      09-25-2007
Hello,
I'm trying to convert xml files to SGML. The publishing system at our
company uses SGML. And, basically, the SGML I want to create is just
CALS, which is the SGML tables standard. So, I'm trying to use REXML to
parse the XML and delineate all of the necessary elements that need to
be converted. And, I need to do some gathering and sorting. My client,
an editor in my company, wants to pick the first from the list of a
series of elements and use that as text for a heading in the final
document.
Here's a bit of the original. I've attached a sample XML file.
<registration>
...
<issueList>
<issue code="ENG">Energy/Nuclear</issue>
<issue code="WAS">Waste (hazardous/solid/interstate/nuclear)</issue>
</issueList>
Here's what I'm doing to just try and capture that first instance of
<issue code>, which, in this case, is "Energy/Nuclear."
codes = XPath.match( doc, "//registration/issueList/issue code[1]" )
puts codes
It's giving me ALL of the <issue code>s, no matter what I put there as a
quantifier. I've tried "[1]", as shown. I've tried [0], first,
[position()<2], but, the results all look the same. It just gives me the
whole list, not the first entries I'm asking for.
Thanks,
Peter

Attachments:
http://www.ruby-forum.com/attachment/391/test1.xml

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Peter Bailey
Guest
Posts: n/a
 
      09-25-2007
Peter Bailey wrote:
> Hello,
> I'm trying to convert xml files to SGML. The publishing system at our
> company uses SGML. And, basically, the SGML I want to create is just
> CALS, which is the SGML tables standard. So, I'm trying to use REXML to
> parse the XML and delineate all of the necessary elements that need to
> be converted. And, I need to do some gathering and sorting. My client,
> an editor in my company, wants to pick the first from the list of a
> series of elements and use that as text for a heading in the final
> document.
> Here's a bit of the original. I've attached a sample XML file.
> <registration>
> ...
> <issueList>
> <issue code="ENG">Energy/Nuclear</issue>
> <issue code="WAS">Waste (hazardous/solid/interstate/nuclear)</issue>
> </issueList>
> Here's what I'm doing to just try and capture that first instance of
> <issue code>, which, in this case, is "Energy/Nuclear."
> codes = XPath.match( doc, "//registration/issueList/issue code[1]" )
> puts codes
> It's giving me ALL of the <issue code>s, no matter what I put there as a
> quantifier. I've tried "[1]", as shown. I've tried [0], first,
> [position()<2], but, the results all look the same. It just gives me the
> whole list, not the first entries I'm asking for.
> Thanks,
> Peter


Never mind. I think I got it. I'm obviously new to XML, so, I was
confused about what's an element and what's an attribute. I did this and
I'm getting closer:

codes = XPath.match( doc, "//registration/issueList/issue[1]/" )

Thanks, anyway.
-Peter

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Keith Fahlgren
Guest
Posts: n/a
 
      09-27-2007
On 9/25/07, Peter Bailey <> wrote:
> > It's giving me ALL of the <issue code>s, no matter what I put there as a
> > quantifier. I've tried "[1]", as shown. I've tried [0], first,
> > [position()<2], but, the results all look the same. It just gives me the
> > whole list, not the first entries I'm asking for.


You may also be interested in XPath.first():
http://www.ruby-doc.org/stdlib/libdo...h.html#M002905


HTH,
Keith

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kamaelia 0.4.0 RELEASED - Faster! More Tools! More Examples! More Docs! ;-) Michael Python 4 06-26-2006 08:00 AM
More Information than just IIS Log Information subrato ASP .Net 8 03-14-2006 09:59 PM
signer information does not match signer information of other classes in the same package clercmedia Java 2 12-09-2005 03:14 PM
With a Ruby Yell: more, more more! Robert Klemme Ruby 5 09-29-2005 06:37 AM
strange information from asp.net trace / getting performance information using WebRequest and StreamReader z. f. ASP .Net 0 02-03-2005 11:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57