Home Answers Viewqa Java-Beginners can't read my xml file in java

 
 


bagas prayogo
can't read my xml file in java
1 Answer(s)      a year and 4 months ago
Posted in : Java Beginners

i've a xml file like this :

 <table ID="customer">
<T>
<C_CUSTKEY>1</C_CUSTKEY>
<C_NAME>Customer#000000001</C_NAME>
<C_ADDRESS>IVhzIApeRb ot,c,E</C_ADDRESS>
<C_NATIONKEY>15</C_NATIONKEY>
<C_PHONE>25-989-741-2988</C_PHONE>
<C_ACCTBAL>711.56</C_ACCTBAL>
<C_MKTSEGMENT>BUILDING</C_MKTSEGMENT>
<C_COMMENT>regular, regular platelets are fluffily according to the even attainments. blithely iron</C_COMMENT>
<abc>abc</abc>
</T>

<T>
<C_CUSTKEY>2</C_CUSTKEY>
<C_NAME>Customer#000000001</C_NAME>
<C_ADDRESS>IVhzIApeRb ot,c,E</C_ADDRESS>
<C_NATIONKEY>15</C_NATIONKEY>
*// nothing <C_PHONE>...</C_PHONE>*
<C_ACCTBAL>711.56</C_ACCTBAL>
<C_MKTSEGMENT>BUILDING</C_MKTSEGMENT>
<C_COMMENT>regular, regular platelets are fluffily according to the even attainments. blithely iron</C_COMMENT>

//nothing ... in this row

and my some java codes :

 private String getResults(TopDocs docs) {
        StringBuilder htmlFormat = new StringBuilder();
        htmlFormat.append("<html><body>");
        htmlFormat.append("ditemukkan sebanyak : <b>" + docs.totalHits +"</b> dokumen <br>");
  for (ScoreDoc sd : docs.scoreDocs) {
            int docId = sd.doc;
            try {
                org.apache.lucene.document.Document doc = searcher.doc(docId);
                htmlFormat.append("<hr>" + "score: ").append(sd.score).append("<br>");
                htmlFormat.append("<b>No.Kustomer</b>: ").append(doc.get("C_CUSTKEY")).append("<br>");
                htmlFormat.append("<b>Nama</b>: ").append(doc.get("C_NAME")).append("<br>");
                htmlFormat.append("<b>Alamat</b>: ").append(doc.get("C_ADDRESS")).append("<br>");
                htmlFormat.append("<b>Kewarganegaraan</b>: ").append(doc.get("C_NATIONKEY")).append("<br>");
                htmlFormat.append("<b>Telepon</b>: ").append(doc.get("C_PHONE")).append("<br>");
                htmlFormat.append("<b>Sisa Saldo</b>: ").append(doc.get("C_ACCTBAL")).append("<br>");
                htmlFormat.append("<b>Segmen</b>: ").append(doc.get("C_MKTSEGMENT")).append("<br>");
                htmlFormat.append("<b>Komentar</b>: ").append(doc.get("C_COMMENT")).append("<br>");
                htmlFormat.append("<b>Tes</b>: ").append(doc.get("abc")).append("<br>");
                } catch (IOException ex) {
                 }
        }
        htmlFormat.append("</body></html>");
        return htmlFormat.toString();
    }

the codes can't read the xml file bcz i want to append the whole xml in my gui. seems the problems is all xml tag must be enum.

can you suggest me how to read the xml file?thx for ur advice

View Answers

January 23, 2012 at 3:40 PM


import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

public class DOMParserExample{
public final static String getElementValue( Node elem ) {
Node node;
if( elem != null){
if (elem.hasChildNodes()){
for( node = elem.getFirstChild(); node != null; node = node.getNextSibling()){
if( node.getNodeType() == Node.TEXT_NODE){
return node.getNodeValue();
}
}
}
}
return "";
}
public static void retrieveValue(Node node,int index) {
String nodeName = node.getNodeName();
String nodeValue=getElementValue(node);
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 1; i++) {
buffer.append(" ");
}
System.out.println(nodeName + " = " + nodeValue);
NodeList children = node.getChildNodes();
for (int i = 1; i < children.getLength(); i++) {
Node child = children.item(i);

if (child.getNodeType() == Node.ELEMENT_NODE) {
retrieveValue(child,index + 2);
}
}
}
public static void main(String[] args) throws Exception {
File f=new File("C:/employee.xml");
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder=docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(f);
Node root = doc.getDocumentElement();
retrieveValue(root,0);
}
}

You can visit the following link in order to check another example:

http://www.roseindia.net/xml/dom/GetData.shtml









Related Pages:
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui..._COMMENT> //nothing ... in this row and my some java codes
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui..._COMMENT> //nothing ... in this row and my some java codes
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui..._COMMENT> //nothing ... in this row and my some java codes
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui..._COMMENT> //nothing ... in this row and my some java codes
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui..._COMMENT> //nothing ... in this row and my some java codes
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui..._COMMENT> //nothing ... in this row and my some java codes
Read XML in java - XML
Read XML in java  Hi Deepak, I want to read a xml file which have only one element with multiple attributes with same tag name. here is my file... a solution.my java code is given below. import java.io.File; import
read XML file and display it using java servlets
read XML file and display it using java servlets  sir, i can't access Xml which is present in my d drive plz can u should go through my code n tell me the things where i went wrong java servlet program protected void
Read XML using Java
of all i need to read xml using java . i did good research in google and came to know...Read XML using Java  Hi All, Good Morning, I have been working... for automating some of the functionaries. And here goes my requirements. Read huge complex
how to read this xml file - XML
how to read this xml file  i want to read this xml file using java... read i have tried lot more , but i am not able to read this xml file... name=client menu=client action=read user employee add
read xml
read xml   hi all, i want to ask about how to read an xml in java ME.. here is the xml file <data> <value> <struct> <member> <name> User_Name
Sorting Xml file - XML
sort my xml file. Here is my xslt.... Thanks.  I am trying to do it with xslt. But it can't sort my xml...Sorting Xml file  I have an xml file like this: Smith USA
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
read xml using java
read xml using java  <p>to read multiple attributes and elements from xml in an order.... ex :component name="csl"\layerinterfacefile="poo.c...;   Please visit the following link: Read XML data
Read the value from XML in java
Read the value from XML in java  Hi, i have an XML...:/Lakki/PermissionCheck/logs/RevAppserver.log") of log file in order to check the permissions on that file.So how can i read that value. This is little urgent
java - XML
This is my XML file then how can read this XML file Using DOM & SAX parsers in java? How can write the same data into XML file using DOM parser? Could you
Java read lines from file
java file line by line. My file is very big around 6.5GB so it's not possible to read the whole file in one go. So, in my case reading file line by line is only...Java read lines from file  Any code example related to Java read
JDOM example in java, How to read a xml file in java.
JDOM example in java, How to read a xml file in java. In this tutorial, we will see how to  read a xml file in java. Code. Student.xml...;     File file = new File(data
Java get XML File
Java get XML File       In this section, you will study how the java application read the XML file. For this, you need to create a XML file. Here is the employee.xml
read xml elements
read xml elements  i want read xml data using sax parser in java. but is there any classes or methods to read xml elements
read xml elements
read xml elements  i want read xml data using sax parser in java. but is there any classes or methods to read xml elements
XML in database - XML
with single element multiple tag in xml. i m trying to read the tag values into my... this xml into my db(which is in mysql) i write the following code. import...("Cannot read the test file: "+e.getMessage
read a file
read a file  read a file byte by byte   import java.io.File... static void main(String[] args) { File file = new File("D://Try.txt"); try { FileInputStream fin = new FileInputStream(file); byte
Read Complex XML using DOM/SAX Parser.
Read Complex XML using DOM/SAX Parser.  I have a XML file which is having two types of Items. I want to extract all details of a type only. My XML goes something like this <Movie> <Bollywood> <Actor> Shah Rukh
How read xml file value in dojox chart - XML
How read xml file value in dojox chart  How to read the xml file value in dojox chart
Read Lines from text file
Read Lines from text file  Here's a brief desc of what my Java code... need to do this for a file with 11 lines. Here's my code while((line... read from the text file and displays the output as desired. Unable to read the rest
xml - XML
xml  hi convert xml file to xml string in java ,after getting the xml string result and how to load xml string result? this my problem pls help... ReadXML(); xml.convert(input, output); System.out.println("XML File
Java + XML - XML
java...the attribute value..not sure now how to read the xml file passing...Java + XML  1) I have some XML files, read one xml..." pointing to a hello xml file ..read that file and get the value of the parent
creating index for xml files - XML
creating index for xml files  I would like to create an index file for xml files which exist in some directory. Say, my xml file is like below... the same structure. It would be like 100 to 200 xml files and each xml file has
java read file
java read file  Hello i need some help... i want to read an MS Excel file in java so how to read that file
Read file in java
Read file in java  Hi, How to Read file in java? Thanks   Hi, Read complete tutorial with example at Read file in java. Thanks
parsing XML file to get java object - XML
parsing XML file to get java object  Hello, I'm facing a problem in parsing XML file to get the java object. I've tried to retrieve data from XML file using SAX parser. my XML file structure is the following
Java-XML-DOM - XML
Java-XML-DOM  Hi! I need some help. I have to make java program that loads an xml file and from it builds DOM(later i will have to work with it - like using xpath in java find some value and replace it...). Since i'm new to java
XML- read Text Mode - Java Error in Windows - reg. - Java Beginners
XML- read Text Mode - Java Error in Windows - reg.  Dear All I'm creating the code as read the XML file in BufferedReader method. Here I pasted the code below:. (*) First read the XML file using FileInputStream
Read from file java
Read from file java  How to Read from file java? What is the best method for a text file having a size of 10GB. Since i have to process the file one line at a time so tell me the very best method. Thank you
Java read binary file
Java read binary file  I want Java read binary file example code... at Reading binary file into byte array in Java. Thanks   Hi, There is many more examples at Java File - Learn how to handle files in Java with Examples
xml file reading using java
xml file reading using java  hi deepak I want to read some data from xml file and send that output to particular email address using java   import org.w3c.dom.*; import org.w3c.dom.Node; import javax.xml.parsers.
Writing xml file - Java Beginners
XmlServlet().createXmlTree(doc); System.out.println("Xml File Created...Writing xml file  Thank you for the quick response The values which you are passing are the predefined ones,but my requirement is to get those
XML
XML  create flat file with 20 records. Read the records using xml parser and show required details
j2me with xml - Java Beginners
j2me with xml   shahzad.aziz1@gmail.com i am working in j2me and i want to read and display data using xml file. In j2me application KXML PARSER is use to read and display data. When i run my application in ?Wireless
how to read values from java in xml?
how to read values from java in xml?  how to read values from java in xml
can't connect to MySQL Server(10060) - JDBC
can't connect to MySQL Server(10060)  Hii Sir, I am working with a jsp project with MySQL as server. Now i want to host my application. I am.... --------------------------------------------------- Read for more
How to Read a file line by line using BufferedReader?
How to Read a file line by line using BufferedReader?  Hello Java... problem is to find the best way to read the file in Java. I just searched the google... at a time very efficiently. View the detailed example and code at Java Read File Line
read from file and store using hash map
read from file and store using hash map  I was stuck with a java project where I have to read a file with two different concepts and store them differently in hashmap. My data file would be something like Adults: Name, xyz
Read and write file
Read and write file  HI, How to read and write file from Java program? Thanks   Hi, See the following tutorials: Java Write To File Read File Thanks
java with xml
example i copmpare qName with NAME. NAME is xml element. but my problem is when xml file change in future then my java code will also change. but is there any... xml file in java DefaultHandler handler = new DefaultHandler
XML Tutorial
kinds of structured information .     The Java /XML Tutorial: the Java XML Tutorial, is an online manual that can quickly get you... the Java API for XML Processing ((JAXP). To focus on XML with a minimum
READ DATA - Java Beginners
to nm_div,Finance go to dep,dsc this my code : try{ // Open the file... = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line...READ DATA  i still don't understand, i have a data like
java - XML
java  how can i validate my xml file using java code plz send me de... kumar  Hi friend, Step to validate a xml file against a DTD (Document Type Definition) using the DOM APIs. Here is the xml file "User.xml
xml displaying a drives data.....
of server directory and generates the XML file. You can read this xml file in java... the XML. Thanks in advance.......   Hi, You can't access the your drive...xml displaying a drives data.....  Hi all, I need a solution

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.