File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes xml parsing 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 "xml parsing" Watch "xml parsing" New topic

xml parsing

rupa kalid

Joined: Jul 26, 2000
Posts: 4
my problem lies in parsing......
an eg of the xml i am trying to parse is

tO parse this file and store the nodes in an array
i use the folloewing code
import org.w3c.dom.*;
public class correct
public static void main(String args[])
String s3[]=null;
String filename = "c:\\my documents\\rupac.xml";
if (filename != null) {
InputStream is;
try {
is = new FileInputStream(filename);}
catch (FileNotFoundException notFound) {

//*** The doc is the root of the DOM Tree. It is of type
//*** TXDocument which implements the DOM Document interface. p = new;
TXDocument doc = p.readStream(is);
//get the root element for this document
TXElement root = (TXElement)doc.getDocumentElement();
public static void printNodes(Node root)
NodeList n1 =root.getChildNodes();
int j=n1.getLength();
String[]s3= new String [j];
String s2=null;
for(int i=0;i<n1.getLength();i++)
if (!n1.item(i).getNodeName().equal("#text"))

System.out.println("The node is " + n1.(i).getNodeName() + " value " + n1.item(i).getNodeValue());
when i do this i get....node is #text....along with the correct nodes......
why do i get #text when there is no #text in my xml
and if i try to remove
these lines of code....then i get rid of #text but all my node values are null
please help
Rama Raju

Joined: Jul 07, 2000
Posts: 12
Hi Rupa,
The xml file written is not well formed. Why don't u write well formed xml and then try.
I agree. Here's the link:
subject: xml parsing
Similar Threads
Display contents in GUI format
Suppress text nodes in output when empty
Why is this happening?
Why I can't retrieve records stored in a XMLFile correctly?
XPath and Modified DOM document object...