getAttribute return null value...
843834Jul 18 2002 — edited Jul 18 2002hi
this is my xml file
<?xml version="1.0" encoding="UTF-8"?>
<invoiceClose>
<line lineNo="1">111</line>
<line lineNo="2">wwwwwwwwww</line>
<line lineNo="3">eeeeeeeeeeeeeee</line>
<line lineNo="4">3333333333</line>
</invoiceClose>
parser program is very simple below
it is giving null values and null pointer exception when i am
getting the attribute value...
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
import java.util.*;
import java.awt.List;
public class sam implements java.io.Serializable
{
static Document d =null;
boolean flag = true;
static NodeList nodelist = null;
static Node node = null;
static Element element =null;
static Vector vectIn =null;
static Vector vectOut =null;
public sam(){
}
public static Document getDocument(String file) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new File(file));
return doc;
}
public static void main(String args[]) {
try{
String filename = "C:\line.xml";
d = getDocument() ;
element = d.getDocumentElement(filename );
nodelist = d.getElementsByTagName("line");
Attribute attr = element.getAttribute("lineNo");
System.out.println("element.hasAttribute(value)"+element.hasAttribute("lineNo"));
System.out.println("Attr "+attr);
Element e = d.getElementById("lineNo");
System.out.println("eeeeeeeee "+e);
}
catch(Exception ex) {
System.out.println("value of Exception is"+ex);
}
}
}
change filename fath accroding to u xml file path...
can any one help me in the regards...
it is very much helpfull for me..
with regards
elan