Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Parsing XML usign Java

  Asked By: Bryant    Date: Jan 18    Category: Java    Views: 665

I have been stuck on this code snippet for a minute
DocumentBuilderFactory factory =
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new
If I do a

System.out.println(doc.getDoctype() );

I get null for both. What am I doing wrong?

My XML is located below. It is not a file. The actual XML is the String:

xml var is:

- <REQUEST TIMESTAMP="2004-01-20 10:49:33.169" TotalDevices="32">
<DEVICE Key="708" SerialNum="00104002EC9C12600300630" />
<DEVICE Key="709" SerialNum="00104002ECAE13300300199" />
<DEVICE Key="710" SerialNum="00104002ECAE13300300199" />
<DEVICE Key="711" SerialNum="00104002ECB413300300205" />
<DEVICE Key="712" SerialNum="00104003011613300300204" />
<DEVICE Key="713" SerialNum="00104003011613300300204" />
<DEVICE Key="714" SerialNum="00104003011B13300300195" />
<DEVICE Key="715" SerialNum="00104003011B13300300195" />
<DEVICE Key="716" SerialNum="00104003609513300300187" />
<DEVICE Key="717" SerialNum="00104003609513300300187" />
<DEVICE Key="718" SerialNum="73513FBF500000831A7286687D090083" />
<DEVICE Key="719" SerialNum="73513FBF500000831A72A228D5070073" />
<DEVICE Key="720" SerialNum="73513FBF500000831A72A228D5070073" />
<DEVICE Key="721" SerialNum="73513FBF500000831A955908D60D00C4" />
<DEVICE Key="722" SerialNum="73513FBF500000831AA24267A7000000" />
<DEVICE Key="723" SerialNum="73513FBF500000831AA24267A7000000" />
<DEVICE Key="724" SerialNum="73513FBF500000831AA957B1C9000090" />
<DEVICE Key="725" SerialNum="73513FBF500000831AAA2AA5AB070066" />
<DEVICE Key="726" SerialNum="73513FBF500000831AAA2AA5AB070066" />
<DEVICE Key="727" SerialNum="73513FBF500000831AAA2AA5AB070066" />
<DEVICE Key="728" SerialNum="73513FBF500000831AAA2AA5AB070066" />
<DEVICE Key="729" SerialNum="73513FBF500000831AAA2AA5AB070066" />
<DEVICE Key="730" SerialNum="73513FBF500000831AAA2AA5AB070066" />
<DEVICE Key="731" SerialNum="73513FBF500000831AAA2AA5AB070066" />
<DEVICE Key="732" SerialNum="73513FBF500000831AAA2AA5AB070066" />
<DEVICE Key="733" SerialNum="EMULATOR" />
<DEVICE Key="734" SerialNum="EMULATOR" />
<DEVICE Key="735" SerialNum="EMULATOR" />
<DEVICE Key="736" SerialNum="EMULATOR" />
<DEVICE Key="737" SerialNum="EMULATOR" />
<DEVICE Key="738" SerialNum="EMULATOR" />
<DEVICE Key="739" SerialNum="EMULATOR" />



1 Answer Found

Answer #1    Answered By: Faith Hughes     Answered On: Jan 18

I am not sure what the problem is. Could you try
running the code  again after prefixing your xml  string
with this string:
<?xml version="1.0"?>

When using file  based xml, this declaration has to be
the first line in my file. Hope it works for you.

Didn't find what you were looking for? Find more on Parsing XML usign Java Or get search suggestion and latest updates.