More information on REXML/XPath

P

Peter Bailey

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
 
P

Peter Bailey

Peter said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top