473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Java & xml Problem

I am new in Java. And asking for help.
The problem is to parse the XML doc and search the parse tree for the
value and then print path to it.
For instance:
XML document:
<1>
<2>
<3>value1</3>
<4>value2</4>
</2>
</1>
c:\ java XMLParser doc.xml value1
path is: 1 -> 2 -> 3

c:\ java XMLParser doc.xml value2
The path is: 1 -> 2 -> 4
Have any ideas?
Thanks for attention
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
3 1360
Brian Terry wrote:
I am new in Java. And asking for help.
The problem is to parse the XML doc and search the parse tree for the
value and then print path to it.
For instance:
XML document:
<1>
<2>
<3>value1</3>
<4>value2</4>
</2>
</1>
c:\ java XMLParser doc.xml value1
path is: 1 -> 2 -> 3

c:\ java XMLParser doc.xml value2
The path is: 1 -> 2 -> 4
Have any ideas?
Thanks for attention
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

So you want us to give you the code??

Maybe you could try it yourself first.
Jul 20 '05 #2
Ok,
i am using dom4j. And have such error:
'Exception in thread "main" java.lang.NoClassDefFoundError:
org/dom4j/io/DOMReader'. Can u help me to solve it? The code is here:

import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.DOMReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.util.Iterator;
import java.util.List;

public class TestSearch {

public static void main(String[] args)
throws Exception {
if (args.length < 2) {
System.out.println("usage: TestSearch file value");
System.exit(0);
}
// parse a DOM tree
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
org.w3c.dom.Document domDocument = builder.parse(args[0]);

// Now convert to DOM4J model
DOMReader reader = new DOMReader();
Document document = reader.read(domDocument);

// List nodes with search value
List nodes = document.selectNodes("//*[starts-with(., '" + args[1] +
"')]");
for (Iterator it = nodes.iterator(); it.hasNext();) {
Node node = (Node) it.next();
if (node.getText().equals(args[1])) {
System.out.println(node.getPath());
}
}

}

}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
Make sure to include dom4j on the classpath.

Regards,
Edwin
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: TI | last post by:
Where would you start if you wanted to program perhaps a java application to enable a bluetooth mobile phone to work as walkie-talkie? ( schematics, compilers... ) thanks
0
by: JShurmatz | last post by:
If anyone can shed some light on this problem I would greatly appreciate it. I am unsuccessfully trying to use a database connnection retrieved from a pool configured using Java System Web...
4
by: Lorenzo | last post by:
hi you all, first of all apologies for having cross-posted this message but really i did not know where to post it. please let me know what ng you consider the most suitable for the described...
8
by: redcard | last post by:
Hi, I'm from a VB background but am having to learn Java for a new project we have at work. Can anyone suggest a decent way to learn it (and fairly fast). Will be using JBuilder 7, have a few...
1
by: C.O.Jones | last post by:
Using Oracle 8.1.7 Personal edition on Windows XP. I was experimenting with the DBA tools. I first of all tried to adjust the memory used by my database. Then I attempted to shutdown and...
1
by: Robert Dodier | last post by:
Hello, Sorry for asking what must be a FAQ, but I wasn't able to find the answer. I have an XML document fragment which I want to store as a text string. I want a function to convert any XML...
16
by: Amir Michail | last post by:
Hi, It seems to me that measuring productivity in a programming language must take into account available tools and libraries. Eclipse for example provides such an amazing IDE for java that it...
3
by: Ludwig Wittgenstein | last post by:
Hello, all. Does anyone know of documentation about implementing a publish- subscribe model between a .NET Web service provide and a Java service consumer? I have this problem I am trying to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.