osdir.com
mailing list archive

Subject: Re: Iterating through XML Elements - How? - msg#00190

List: jakarta.velocity.user

Date: Prev Next Index Thread: Prev Next Index
Hello Terry,

Terry Steichen wrote:
>
> From: "Geir Magnusson Jr." <geirm@xxxxxxxxxxxxx>
> > > Appreciate knowing what I'm missing here. I kind of suspect it has
> something
> > > to do with the need to use an iterator, but not sure.
> >
> > That's the right idea.
>
> OK - I give up. What's the right idea? How do I use iterators here?
>
> > Question - why not use dom4j? You can use Xpath, and it returns normal
> > java.util.Lists....
>
> At the moment, the DOM document is generated by JTidy, because it 'cleans it
> up' before I work with it.
>
>
> So back go the original question: How can I iterate through a NodeList with
> #foreach()?

Okay. Then like Geir said, try dom4j. It can convert DOM to dom4j's node
model. See http://www.dom4j.org/cookbook/cookbook.html#NB2C for more
info. Also, if jTidy can generate SAX events you could have dom4j read
those from jTidy.

Another option is to write a little class that implements Iterator and
given a DOM NodeList could traverse it.

-Bill

--
To unsubscribe, e-mail: <mailto:velocity-user-unsubscribe@xxxxxxxxxxxxxxxxxx>
For additional commands, e-mail: <mailto:velocity-user-help@xxxxxxxxxxxxxxxxxx>




Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Re: Iterating through XML Elements - How?

From: "Geir Magnusson Jr." <geirm@xxxxxxxxxxxxx> > > Appreciate knowing what I'm missing here. I kind of suspect it has something > > to do with the need to use an iterator, but not sure. > > That's the right idea. OK - I give up. What's the right idea? How do I use iterators here? > Question - why not use dom4j? You can use Xpath, and it returns normal > java.util.Lists.... At the moment, the DOM document is generated by JTidy, because it 'cleans it up' before I work with it. So back go the original question: How can I iterate through a NodeList with #foreach()? Regards, Terry -- To unsubscribe, e-mail: <mailto:velocity-user-unsubscribe@xxxxxxxxxxxxxxxxxx> For additional commands, e-mail: <mailto:velocity-user-help@xxxxxxxxxxxxxxxxxx>

Next Message by Date: click to view message preview

Re: Iterating through XML Elements - How?

On 3/21/02 6:54 PM, "bob mcwhirter" <bob@xxxxxxxxxx> wrote: > On Thu, 21 Mar 2002, Terry Steichen wrote: > >> I've generated an XML document (org.w3c.dom.Document) and inserted it >> into the context. My template can use all the Document methods just fine. >> My problem is that when I do something like getElementsByTagName() >> to return a Nodelist, I can't figure out how to use #foreach() to work >> with it. > > Not certain if this will answer your question as to why foreach isn't > working as you expect it to, but Jaxen (http://jaxen.org/) can help > you work with XML object-models (DOM, JDOM, dom4j, EXML). Using > XPath, you can extract whatever data portions you need. > > If you like JDOM, then Anakia (part of Velocity) is also a nice > way to go. SomeDay(tm), I plan on re-working Anakia to use Jaxen > instead of werken.xpath, so that more than just JDOM is supported. All you have to do is release Jaxen... :) -- Geir Magnusson Jr. geirm@xxxxxxxxxxxxx System and Software Consulting The question is : What is a Mahnamahna? -- To unsubscribe, e-mail: <mailto:velocity-user-unsubscribe@xxxxxxxxxxxxxxxxxx> For additional commands, e-mail: <mailto:velocity-user-help@xxxxxxxxxxxxxxxxxx>

Previous Message by Thread: click to view message preview

Re: Iterating through XML Elements - How?

From: "Geir Magnusson Jr." <geirm@xxxxxxxxxxxxx> > > Appreciate knowing what I'm missing here. I kind of suspect it has something > > to do with the need to use an iterator, but not sure. > > That's the right idea. OK - I give up. What's the right idea? How do I use iterators here? > Question - why not use dom4j? You can use Xpath, and it returns normal > java.util.Lists.... At the moment, the DOM document is generated by JTidy, because it 'cleans it up' before I work with it. So back go the original question: How can I iterate through a NodeList with #foreach()? Regards, Terry -- To unsubscribe, e-mail: <mailto:velocity-user-unsubscribe@xxxxxxxxxxxxxxxxxx> For additional commands, e-mail: <mailto:velocity-user-help@xxxxxxxxxxxxxxxxxx>

Next Message by Thread: click to view message preview

Re: Iterating through XML Elements - How?

On Thu, 21 Mar 2002, Terry Steichen wrote: > I've generated an XML document (org.w3c.dom.Document) and inserted it > into the context. My template can use all the Document methods just fine. > My problem is that when I do something like getElementsByTagName() > to return a Nodelist, I can't figure out how to use #foreach() to work > with it. Not certain if this will answer your question as to why foreach isn't working as you expect it to, but Jaxen (http://jaxen.org/) can help you work with XML object-models (DOM, JDOM, dom4j, EXML). Using XPath, you can extract whatever data portions you need. If you like JDOM, then Anakia (part of Velocity) is also a nice way to go. SomeDay(tm), I plan on re-working Anakia to use Jaxen instead of werken.xpath, so that more than just JDOM is supported. -bob -- To unsubscribe, e-mail: <mailto:velocity-user-unsubscribe@xxxxxxxxxxxxxxxxxx> For additional commands, e-mail: <mailto:velocity-user-help@xxxxxxxxxxxxxxxxxx>
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by