aspose file tools*
The moose likes XML and Related Technologies and the fly likes what's the best way to extract multiple attributes from anode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "what Watch "what New topic
Author

what's the best way to extract multiple attributes from anode

carlos flamenco
Greenhorn

Joined: Feb 28, 2001
Posts: 7
hi,
I'm wondering if i should be using getAttributes from xml paser to extract the attributes in the item node.
I wish to insert the data into a database. At the moment i'm just using selectNodes, but i'm having to initialise a nodelist for each of the items i wish to extract, there is 6 of them in total.
Anybody have any ideas?
<item date="2001-02-27" itemid="30737" parts="1" revision="3" href="30737.xml"
<title>Paper</title>
</item>

Thanks
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
DOM is good, JDOM is better. I can't think of any other better way.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

In SAX, one would do this to extract attributes:-

Pho
[This message has been edited by Pho Tek (edited March 15, 2001).]
[This message has been edited by Pho Tek (edited March 15, 2001).]


Regards,

Pho
ARS Kumar
Ranch Hand

Joined: May 22, 2000
Posts: 108
Using DOM parser xerces.jar from http://xml.apache.org we can get into the attributes by
NamedNodeMap attrs = node.getAttributes();

if (attrs != null) {
attributes += attrs.getLength();

for(int i=0;i < attrs.getLength();i++){
System.out.println("Attributes :: " + attrs.item(i).toString());
Attr atr = (Attr)attrs.item(i);
System.out.println(" Name of Attribute :: " + atr.getName());
System.out.println(" Value of Attribute :: " + atr.getValue());
}
}
Attr is the interface that deals with attributes. Refer to xerces documentation for more informaion.

------------------
ARS Kumar
Sun Certified Programmer for Java 2 Platform.


ARS Kumar, Sun Certified Programmer for Java 2 Platform
http://www.automatedsqa.com/
Kamakshi Mahadevan
Greenhorn

Joined: Nov 08, 2000
Posts: 18
Just noted that:
In the above code,
System.out.println("Attributes :: " + attrs.item(i).toString());

is equivalent to:
Attr atr = (Attr)attrs.item(i);
System.out.println(" Name of Attribute :: " + atr.getName());
System.out.println(" Value of Attribute :: " + atr.getValue());
so either will suffice.
[This message has been edited by Kamakshi Mahadevan (edited March 20, 2001).]
[This message has been edited by Kamakshi Mahadevan (edited March 20, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what's the best way to extract multiple attributes from anode