how can i search for an atributte in a xml document
1 posts in topic
Flat View  Flat View

Posted By:   Roberto_Ortega
Posted On:   Wednesday, June 5, 2002 02:19 AM

I´m new in xml and i´m developin an aplication where i need to read the value of the node where an atribute called Nombre have a know value.

for example i have the xml

<?xml version="1.0"?>

one value i need

other value i need

and i need to search in the xml which node have the atribute Nombre = ficherox.pdf to get their value.

thanks to all

Re: how can i search for an atributte in a xml document

Posted By:   murali_krishna  
Posted On:   Wednesday, June 5, 2002 03:51 AM

U can get all the attributes for the element "Fichero" using the following code. From that if u want only attribute "Nombre" u can do so.

public static void main(String args[])
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringElementContentWhitespace(true) ;
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new File("ficheros.xml"));

Element root = doc.getDocumentElement();
System.out.println("Root Element: "+root.getNodeName());
NodeList nl = root.getElementsByTagName("Fichero");
Node vnode;
NamedNodeMap nm;
for(int j=0;j {

vnode = nl.item(j);
nm = vnode.getAttributes();
for(int i=0;i {
Node attr = nm.item(i);

}catch(Exception e)
System.out.println("Error: "+e);
About | Sitemap | Contact