how to fetch a value from persistence.xml to build.properties?

XML DOM Help needed

  • XML DOM question: Help a newbie. I can't figure out how to do something that seems so simple. I'm writing an extremely simple RSS reader that creates a select control. Each option element needs only to be filled with the values of the "link" and "title" elements but I can't figure out how to reference them by name. In the RSS its basicaly only the "item" elements i'm interested in and "link" and "title" are two elements which are its children that I need to fetch the values for Heres my initial code (ASP): ------------------------------------------------------------------------- Set Root=source.documentElement Set PodcastList=Root.getElementsByTagName("item") For Each Podcast In PodcastList Set Podcast_URL = [HOW?] Set Podcast_title = [HOW?] Response.write("<option value=""" & Podcast_URL.text & """>" & Podcast_URL.text & "</option>") Next -------------------------------------------------------------------------- What I can't figure out is how to request just the element i want by its name without using getelementsbyname() since that returns a list and there seem to be properties available to return single elements like firstChild or lastChild so it seems logical that there would be a method to do it for a single named element. I know xpath is probably what I need but i'm not at the learning stage where I know how to incorporate that into my code. Thanks for your help!

  • Answer:

    I think the list getelementsbyname() returns is an array, so if you know there is only one element with that name, then you can safely retrieve the name by index 0 so if x=getelementsbyname("myname"); then x[0] gives you the element you want.

postergeist at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

You can also call getElementsByTagName as a method on a DOM node to restrict its scope to the contents of that node. In other words if you want to iterate over each item element and work with the link and title elements inside them, you could do (in JavaScript):var items = document.getElementsByTagName("item");for (var i = 0, len = items.length; i var link = items[i].getElementsByTagName("link")[0]; var title = items[i].getElementsByTagName("title")[0]; // Do what you need to do here with link and title}>(Note the [0] array index notation there which assigns just the first node returned into the variable, since the method returns an array of nodes.) If those nodes contain just text, you can look at their first child elements respectively (which will be text nodes) and use the nodeValue attribute to get the actual text contents.

letourneau

I don't know what the heck that br> is doing on the second line of my code sample, but you get the picture.

letourneau

Thanks, this is now working for me! I used the getelementsbyname method and am grabbing the first index position. I was surprised though that there was no other way to do this? It seems that this should be possible somehow considering that xpath contains all these capabilities. Something about having to read all the child elements called "link" into an array even though I know there is only one in the schema seems inefficient.

postergeist

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.