Win a copy of Event Streams in Action this week in the Java in General forum!

Brooklyn Luo

Greenhorn
+ Follow
since Jun 28, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Brooklyn Luo

Originally posted by Michael Ernest:
What version of Xerces are you using?


I figured out the problem. It seems the Xerces parser 1.4.3 I used may not support in parsing the document out of a ServletInputStream.
I tried the Xerces 2.0. But it seems it conflicted with my other codes and cause other problems.
So I tried another way by creating a inputsource object from a String containning the XML content. And it worked.
The reason Xerces parser complained is the XML file servlet received contains some content header and form name value .... stuff like that. That's the reason Xerces parser 1.4.3 can't recognize the XML file.
I did it as follows:
String xmlString ="";
BufferedReader br = new BufferedReader( new InputStreamReader ( req.getInputStream(),"ISO-8859-1" ), 1024);
for (int i=0; (line=br.readLine())!=null;i++) {
xmlString += line;
// only grab the XML content and remove others.
index = xmlString.indexOf("<?");
lastIndex = xmlString.lastIndexOf(">");
xmlString = xmlString.substring(index,lastIndex+1);

DOMParser ps = new DOMParser();
InputSource is = new InputSource (new StringReader (xmlString));
ps.parse(is);

Another thing is when uploading the file, the form need to have ENCTYPE="multipart/form-data" as one attribute. It will cause other <input> name value in the form invalid. It seems server won't received other name value pairs using request.getParameter("..").
So if you want to forward some parameter to server side, you need to append the name value pair at the action part like the following:
<form ENCTYPE="multipart/form-data" ACTION="/SomeServlet?name=<%= value %>" METHOD="POST">

I still don't think I did it efficiently, If Michael or anyone have experience in handling the upload XML files, which parse can do the work, etc, please reply, thanks!
I am doing a project requiring me to parse the XML file uploaded from client side.
In client side, the uploading page contains:
<form ENCTYPE="multipart/form-data" ACTION="XMLUploadServlet" METHOD="POST">
...
</form>
In server side, a Servlet handles the request. In doPost method of this servlet:

Xerces parser is usded.
After I ran the program, I got the following exception:
org.xml.sax.SAXParseException: The root element is required in a well-formed document.

But the XML file is valid against the DTD along with it.
Any one has the similar experience?
Any suggestion is appreciated.
Thanks in advance!
TO Alex Ayzin:
I didn't have any XML experience before studying for the exam.
I studied around 2-3 hours every day for about two months.
Before planning to take the exam, I found almost all of the previous test takers are experienced programmer. So I spend
a lot time reading articles from different websites.
But I don't think this help me much.
To Michael.H.Sun:
If you keep searching or visiting this forum, you will find
a lot of useful information. http://www.javaranch.com/gramps/XMLLinks.jsp
I used this link a lot.


passed IBM XML Certification this morning.
Now I'm qualified for the following titles:
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
I got only 64%. I could not prepare to my satisfaction because I will graduate this Aug, I hope these two certifications and a master degree in computer engineering will help me to land a entry-level job.

Time is very critical for me to answer all 74 questions.
I suggest the follwing readings:
For "XML and DTD", I think XML Bible is good enough.
For XSLT, I use �XSLT. Working with XML and HTML".
For DOM and SAX, I use "Beginning XML".
Tutorials from http://www.zvon.org/ help me a lot to understand
some concepts.
I did very bad in XML Rendering only 25%.
But 88% on design.
I thank all the previous test takers who gave valuable suggestions that helped me to get this certification.
Thank you and Good Luck to all of you.
I have 2 questions regarding DOM/SAX test from Java Ranch's XML Exam List.
4.There is XML data document which is very large. The application is to extract the very few of its information from document. The memory & speed may be a constraint. Which is the most likely method to be implemented?
a) Extract the information using SAX API, event based methods.
b) To extract the information using DOM API.
c) To extract the necessary information and process using XSLT.
d) To use schema based approach.
Answer:b
Can someone tell me why a is not correct?
11. Use of SAX based parser is most likely to be used in which of the following scenarios?
a) You want to process the document in a sequential order only.
b) The documents is very large.
c) When there is no need to validate XML documents.
d) The parser implements only SAX based approach.
Answer:a
I think b is also OK.

Thanks