This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xml parsing" Watch "xml parsing" New topic
Author

xml parsing

rupa kalid
Greenhorn

Joined: Jul 26, 2000
Posts: 4
Hi,
my problem lies in parsing......
an eg of the xml i am trying to parse is
<MarketingManager>
<partnerChannelForecast>
"yes"
<display>
<control>select
<button>radio</button>
<multipleChoice>no</multipleChoice>
</control>

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) {
System.err.println(notFound);
return;
}

//*** 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();
printNodes(root);
}}
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"))
s2=n1.item(i).getNodeName();
s3[i]=s2;

System.out.println("The node is " + n1.(i).getNodeName() + " value " + n1.item(i).getNodeValue());
printNodes(n1.item(i));
}
}
}
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
s2=n1.item(i).getNodeName();
s3[i]=s2
these lines of code....then i get rid of #text but all my node values are null
please help
Rama Raju
Greenhorn

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.
Ram.
 
I agree. Here's the link: http://aspose.com/file-tools
 
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...