Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Java XML Tree Reading continued

Posted on 2006-04-18
4
Medium Priority
?
173 Views
Last Modified: 2010-03-31
Hello,
I have a program which loads an XML document as its config file. I use xpath to retrieve items from it, however, I need to be able to get the names of sub node values (not sure if I am explaining this right). Here is a chunk of the xml config:

<mtas>
      <mta1>
        <bind_ip>192.168.1.115</bind_ip>
        <mta_name>mx1.goforit.com</mta_name>
        <mta_port>25</mta_port>
        <mta_distributor_connections>5</mta_distributor_connections>
        <mta_distribute_to>192.168.1.115</mta_distribute_to>
        </mta1>

      <mta2>
<bind_ip>192.168.1.115</bind_ip>
<mta_name>mx2.goforit.com</mta_name>
<mta_port>25</mta_port>
<mta_distributor_connections>5</mta_distributor_connections>
<mta_distribute_to>192.168.1.115</mta_distribute_to>
</mta2>
-
      <mta3>
<bind_ip>192.168.1.115</bind_ip>
<mta_name>mx3.goforit.com</mta_name>
<mta_port>25</mta_port>
<mta_distributor_connections>5</mta_distributor_connections>
<mta_distribute_to>192.168.1.115</mta_distribute_to>
</mta3>
-
      <mta4>
<bind_ip>192.168.1.115</bind_ip>
<mta_name>mx4.goforit.com</mta_name>
<mta_port>25</mta_port>
<mta_distributor_connections>5</mta_distributor_connections>
<mta_distribute_to>192.168.1.115</mta_distribute_to>
</mta4>
-
      <mta5>
<bind_ip>192.168.1.115</bind_ip>
<mta_name>mx5.goforit.com</mta_name>
<mta_port>25</mta_port>
<mta_distributor_connections>5</mta_distributor_connections>
<mta_distribute_to>192.168.1.115</mta_distribute_to>
</mta5>
</mtas>

as you can see under the <mtas> tag I have 5 other structures defined. I need to be able to retrieve a list of these structures by name and have them returned to me as a comma delimited string... ie I would call a function called getValueList("root/mtas") and it would return to me mta1,mta2,mta3,mta4,mta5.

Worth 500 points.

Thanks,
Rick
   
0
Comment
Question by:richardsimnett
  • 2
  • 2
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 16482459
be something like:

NodeList nodeList = (NodeList) xpath.evaluate("root/mtas/*, document, XPathConstants.NODESET);
0
 

Author Comment

by:richardsimnett
ID: 16482525
objects,
Ok from looking at the API I get how to work with a nodelist... however, which function do I use on the individual Node to get the name mta1, etc...?

Thanks,
Rick
0
 
LVL 92

Expert Comment

by:objects
ID: 16482546
0
 

Author Comment

by:richardsimnett
ID: 16482638
Objects,
Thanks for your help... got this working very nicely.

-Rick
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question