Quote Originally Posted by Deliverance
Well it's been a little while since I've done XML manipulation in Java, but I remember when I did something similar to this, only my source was over a socket instead of from a file, but that should be irrelevant, you'll have to do something like this to turn your XML into a Document type, which can be parsed from there.

Code:
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new InputSource(new StringReader(xmlSchema))); //where xmlSchema is my String
traverseSchema(doc); //my function to parse the state machine represented by XML
So now that you're here, you will have Node and NodeList manipulation, based on what you're looking for. I had many element which had attributes like yours, and I was looking for occurences of them.

But given your structure, say you have your Node (a Node will be in your case, a single one of your Nodes in your example), you could obtain the attributes by

Code:
Node myNode;
... //some extraction of your Node
myNode.getAttributes().getNamedItem("name").getNodeValue(); //returns name1
I should mention that I was using the following classes:

Code:
javax.xml.parsers.DocumentBuilder;
javax.xml.parsers.DocumentBuilderFactory;
org.w3c.dom.Document;
org.w3c.dom.NamedNodeMap;
org.w3c.dom.Node;
org.w3c.dom.NodeList;
If you're still stuck, just reply I'll see if I can give you a more concrete example if it's required. The Java API describes all this.
hi,thx a lot for your solution, will try this out and let you know.
I have got many solution on net for nodes like
<a>xyz</a> but in my case i had more than one value : <a id=1 name=n> and some thing like that. for that i was looking for here. And i hope that your code snippet will work for my case.