Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getAttribute return null value...

843834Jul 18 2002 — edited Jul 18 2002
hi
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 15 2002
Added on Jul 18 2002
2 comments
316 views