This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes XML and Related Technologies and the fly likes RootElement is null Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "RootElement is null" Watch "RootElement is null" New topic
Author

RootElement is null

Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

Hi All,
I am just learning about XML, and I have a strange problem with an exercise in my book. I am trying to load an XML document with JavaScript, but after it is loaded, browser complains that RootElement is null. The filename is definitely correct and the XML file is "well-formed." I can load other XML files from other exercises using the same JavaScript just fine (just changing the filename in the load() method). Could someone please take a look at the code below, and see if they can find a problem. I am stumped! Thanks a lot!!!
The XML:

The HTML and JavaScript:


[This message has been edited by Barry Andrews (edited January 01, 2002).]
YanNaing WTint
Ranch Hand

Joined: Oct 30, 2001
Posts: 40
Barry,
There is a problem with specifying xml namespace,<i>dt</i> in your xml file at the root element, Book. Change <b>urn</b> to <b>uri</b>.
xmlns:dt="uri:schemas-microsoft-com:datatypes"
Hope it will work.

------------------
Yan Naing Wynn Tint (SCJP2, SCWCD)


Yan Naing Wynn Tint (SCJP2, SCWCD)
YanNaing WTint
Ranch Hand

Joined: Oct 30, 2001
Posts: 40
Barry,
my previous solution is not a correct and proper way.
"urn:schemas-microsoft-com:datatypes" is the correct usage for Unified Resource Name.
The namespace you are using is microsoft datatype schema defination. And the field for that schema is "type". So you must use "dt:type" instead of "dt:dt".
you can check more info at..
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/xml_tutorial_3x2r.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_cdo_schema_datatypes.asp

------------------
Yan Naing Wynn Tint (SCJP2, SCWCD)
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

YanNaing,
Thanks for your reply! But, if I load another XML file that uses "dt:dt" it works fine, which makes me think there is some other problem. Nevertheless, I will try your suggestion to see if it makes a difference.
Thanks,
Barry
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

YanNaing,
Now I am a little confused. I changed the "dt t" to "dt:type" in my XML code, and it worked just like you said it would. But, I have many other examples (all from the book) that I have been using successfully with "dt t". Do you or anyone else have any ideas as to why this is?
Thanks,
Barry
YanNaing WTint
Ranch Hand

Joined: Oct 30, 2001
Posts: 40
Barry,
That is an interesting story. Would you give me one of the other working example using dt t. Let me take a look at it. BTW, what brower and version are you using?
Here is the good tutorial, I hope it would help your learning.
web page
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

Here is one that works using "dt:dt". I am using IE6.0. Thanks for the tutorial!
YanNaing WTint
Ranch Hand

Joined: Oct 30, 2001
Posts: 40
Barry,
Good News.
The problem is at <PublicationDate dt:dt="date">12/20/99</PublicationDate>. In fact, the format of the element content,"12/20/99". The schema that allow the date data type is "CCYY-MM-DD". I think this is MS Xml schema specification. The correct one is like <PublicationDate dt:dt="date">1999-12-20</PublicationDate>.
good luck,
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

Ohhhhhhhhhhhhhhhhhh!!! I see! Yes, that is the problem! I am using BEA XML Editor. It has a parsing feature, but I guess it doesn't actually validate the datatypes. I guess that is asking to much... Thank you very much for your help!

Barry
YanNaing WTint
Ranch Hand

Joined: Oct 30, 2001
Posts: 40
You are very welcome....
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: RootElement is null
 
Similar Threads
Converting an XML document to HTML using Javascript and HTML
XML DOM is not working
XML Scripting is not working
Can you find the bug in <div> I do NOT get sample xml data[bookrss.xml]... RSS Client/Server
serious problem about script loading