Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Java & xml Problem

Reply
Thread Tools

Java & xml Problem

 
 
Brian Terry
Guest
Posts: n/a
 
      03-07-2005
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!
 
Reply With Quote
 
 
 
 
Tjerk Wolterink
Guest
Posts: n/a
 
      03-07-2005
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.
 
Reply With Quote
 
 
 
 
Brian Terry
Guest
Posts: n/a
 
      03-08-2005
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!
 
Reply With Quote
 
Edwin Dankert
Guest
Posts: n/a
 
      03-13-2005
Make sure to include dom4j on the classpath.

Regards,
Edwin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem to insert an XML-element by XSLT-converting from one XML-file into another XML-file jkflens XML 2 05-30-2006 09:41 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Print XML parsing to JspWriter (out) Class org.xml.sax.helpers.NewInstance can not access a member of class javax.xml.parsers.SAXParser with modifiers "protected" Per Magnus L?vold Java 0 11-15-2004 02:27 PM
What XML technologies to learn first for "XML Processing" and "XML Mapping"? Bomb Diggy Java 0 07-28-2004 07:26 AM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM



Advertisments