• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

xml parsing

Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 com.ibm.xml.parser.*;
import org.w3c.dom.*;
import java.io.*;
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.
com.ibm.xml.parser.Parser p = new com.ibm.xml.parser.Parser(filename);
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rupa,
The xml file written is not well formed. Why don't u write well formed xml and then try.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!