xml-beginner

M

Martin Uruz

hi all
i hav a little beginner problem:
i use rexml on ruby 1.8
and the following xml:
<tagebuch>
<monat id="3">
<eintrag>
<datum>12.3.2004</datum>
<text>text ist das</text>
<imagelink>/imqqqqqest.gif</imagelink>
</eintrag>
</monat>
<monat id="4">
.............
</tagebuch>

ans i try to access the datum with this code
doc.elements.each("tagebuch/monat/eintrag") { |element| puts
element.elements["datum"]}

and i get
<datum>12.3.2004</datum>
......
must i strip the tags with a regex ? i think there must be a better way
to do this.


--
thx
martin pfeffer
at
suse 9.0
Apache 2.0
http://eurowalker.is.dreaming.org
 
M

messju mohr

hi all
i hav a little beginner problem:
i use rexml on ruby 1.8
and the following xml:
<tagebuch>
<monat id="3">
<eintrag>
<datum>12.3.2004</datum>
<text>text ist das</text>
<imagelink>/imqqqqqest.gif</imagelink>
</eintrag>
</monat>
<monat id="4">
.............
</tagebuch>

ans i try to access the datum with this code
doc.elements.each("tagebuch/monat/eintrag") { |element| puts
element.elements["datum"]}

and i get
<datum>12.3.2004</datum>
......
must i strip the tags with a regex ? i think there must be a better way
to do this.

element.elements["datum"].text gives you the first child text-element.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top