-4

Possible Duplicate:
What Java XML library do you recommend (to replace dom4j)?

I have been googeling for some days now and can't seem to find the right answer to my challenge.

This is what the items in my xml file looks like.

<Item ItemNo="319097" Name="PCB SIO_1" Value="" Config="1" /> 

I would like to take every single part of this item line and break down into strings like this:

 String ItemNo = "319097";

So that I can create a string array that consists of the values in side the "" in the item node of the XML file.

Is this possible?

In advance thanks for helping me.

8
  • You can use the JDOM library to parse the document. There are lots of code snippets for that in the internet. Commented Dec 16, 2011 at 11:04
  • Possible duplication Commented Dec 16, 2011 at 11:04
  • 1
    Presonally, I would use XSLT for that, not Java, but that is only my opinion. Commented Dec 16, 2011 at 11:04
  • jaxb.java.net/tutorial Commented Dec 16, 2011 at 11:04
  • 3
    "Googling for days"? Crazy. "Challenge"? I think not. Commented Dec 16, 2011 at 11:05

2 Answers 2

4

The cleaneast way would be to unmarshall the XML using Jaxb or something like Xstream : you create a Java object that represent your XML and then Jaxb will create an object and populate it with the XML values. An example for your XML would be :

public class Item {
   private String itemNo;
   private String name;
   private String value;
   private String config;
   ... GETTERS / SETTERS
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can use the DOM API (among others) to select all Item elements and then go though the attributes. A nice library for this is Dom4j. You can find some useful code snippets here: http://dom4j.sourceforge.net/dom4j-1.6.1/guide.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.