File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Engineering
»
XML and Related Technologies
Author
Reading XML Values
Raistlen Majere
Greenhorn
Joined: Aug 03, 2009
Posts: 13
posted
Sep 11, 2009 10:58:42
0
I want to retrieve all values from an xml no matter what the tag. Currently I have the code working for a normal xml:
ArrayList xmlHold = new ArrayList(); //get the root element Element docEle = document.getDocumentElement(); //get a nodelist elements NodeList nl = docEle.getElementsByTagName("*"); if(nl != null && nl.getLength() > 0) { for(int i = 0 ; i < nl.getLength();i++) { //get the element Element el = (Element)nl.item(i); String version = el.getTextContent(); if (version != null | version != "") { xmlHold.add(version.trim()); } } }
The problem I am having is when I need to read the value of a tag in the following format:
<import resource="somecustomconfig.xml" />
I need to extract the "somecustomconfig.xml" and I can not get it to work. Is there a quick fix to this using my current code structure?
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32611
4
posted
Sep 11, 2009 11:23:16
0
Too difficult a question for "beginning Java". Moving.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
I like...
posted
Sep 11, 2009 13:19:08
0
element.getAttribtue(
String
name)
?
Raistlen Majere
Greenhorn
Joined: Aug 03, 2009
Posts: 13
posted
Sep 11, 2009 13:53:48
0
element.getAttribtue(String name)
The only problem is I will not know the contents of the xml, so I can not pass it name parameter.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
I like...
posted
Sep 11, 2009 16:13:02
0
You're reading random XML?
public
NamedNodeMap
getAttributes()
Reading the API will help you.
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Reading XML Values
Similar Threads
xml tags writing
[JAVA] XML reader
JAXB namespace use in XML files
need help in edit the xml using dom parser
Dom parser for XML file
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter