R
rafiamar
hello,
if anyone could help me i'll be grateful
i have this xml:
<?xml version="1.0" encoding="UTF-8"?>
<appage_db>
<cycle id="Pete">
<machine>"t" </machine>
<passwd>"403" </passwd>
<user>"766" </user>
</cycle>
<cycle id="Pro">
<machine>"p" </machine>
<passwd>"411" </passwd>
<user>"766" </user>
</cycle>
</appage_db>
and i have this code:
class ProcessFruits {
public static void main (String[] args) {
try {
javax.xml.parsers.DocumentBuilderFactory factory =
javax.xml.parsers.DocumentBuilderFactory.newInstance();
javax.xml.parsers.DocumentBuilder domBuilder =
factory.newDocumentBuilder();
org.w3c.dom.Document xmlDocument = domBuilder.parse(new
java.io.File("c:\\fff_config.xml"));
org.w3c.dom.NodeList Cycle =
xmlDocument.getElementsByTagName("cycle");
System.out.println("Found " + Cycle.getLength() + "
elements:");
for (int i = 0; i < Cycle.getLength(); i++) {
System.out.println("<Cycle> element " + (i + 1) + ":");
org.w3c.dom.NodeList Descendants =
((org.w3c.dom.Element)Cycle.item(i)).getElementsByTagName("*");
for (int j = 0; j < Descendants.getLength(); j++) {
org.w3c.dom.Node node = Descendants.item(j);
if (node.getChildNodes().getLength() == 1) {
System.out.println("element " + node.getNodeName() +
":" + node.getFirstChild().getNodeValue());
}
}
}
}
catch (Exception e) {
System.out.println(e);
}
} }
I need to get the elements only from the node which has the "id" i want
this program shows all elements.
thanks guys
Rafael Amar
Reply
if anyone could help me i'll be grateful
i have this xml:
<?xml version="1.0" encoding="UTF-8"?>
<appage_db>
<cycle id="Pete">
<machine>"t" </machine>
<passwd>"403" </passwd>
<user>"766" </user>
</cycle>
<cycle id="Pro">
<machine>"p" </machine>
<passwd>"411" </passwd>
<user>"766" </user>
</cycle>
</appage_db>
and i have this code:
class ProcessFruits {
public static void main (String[] args) {
try {
javax.xml.parsers.DocumentBuilderFactory factory =
javax.xml.parsers.DocumentBuilderFactory.newInstance();
javax.xml.parsers.DocumentBuilder domBuilder =
factory.newDocumentBuilder();
org.w3c.dom.Document xmlDocument = domBuilder.parse(new
java.io.File("c:\\fff_config.xml"));
org.w3c.dom.NodeList Cycle =
xmlDocument.getElementsByTagName("cycle");
System.out.println("Found " + Cycle.getLength() + "
elements:");
for (int i = 0; i < Cycle.getLength(); i++) {
System.out.println("<Cycle> element " + (i + 1) + ":");
org.w3c.dom.NodeList Descendants =
((org.w3c.dom.Element)Cycle.item(i)).getElementsByTagName("*");
for (int j = 0; j < Descendants.getLength(); j++) {
org.w3c.dom.Node node = Descendants.item(j);
if (node.getChildNodes().getLength() == 1) {
System.out.println("element " + node.getNodeName() +
":" + node.getFirstChild().getNodeValue());
}
}
}
}
catch (Exception e) {
System.out.println(e);
}
} }
I need to get the elements only from the node which has the "id" i want
this program shows all elements.
thanks guys
Rafael Amar
Reply