• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display XML/HTML file in TextArea in Web page

 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please advice me by code example to show how to display XML/HTML files from client-side hard driver in a textarea.
Here is my jsp page:
<HTML>
<HEAD>
<TITLE>Validate XML Document</TITLE>
</HEAD>
<BODY>
<FORM name="View" method="POST"><B>Select XML File: </B>
<INPUT type="File" name="userFile" size="20">
<INPUT type="submit" name="btnOpen" value="Open"><BR><BR>
<textarea rows="20" cols="62" name="xmlDocument" WRAP="off"></textarea><BR><BR>
<INPUT type="button" value="Validate">
<INPUT type="submit" name="btnUpdate" value="Update">
<INPUT type="submit" name="btnClose" value="Close">
</FORM>
</BODY>
</HTML>
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

/Rene
[ July 16, 2002: Message edited by: Rene Larsen ]
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rene,thank you very much for your help. I'm very happy with your solution. I would greatly preciate it if you could advice me how to validate the XML file.
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rene, I just found that this app doesn't handle error when the user inputs wrong file's name (file is not exsiting). Can you please help me fix this problem?
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've redesigned the earlier solution a little bit

Try this link as well:
http://java.sun.com/j2se/1.3/docs/api/java/io/File.html
/Rene
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you only are using IE as browser then you can use this javascript to validate the xml.

otherwise you need to use a XML parser with either a DTD document or a XML Schema.
/Rene
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rene,
Thanks again! I have one more question for you. Why can't reset the textarea after load the xml document? I changed the close button to "Reset" button (<input type="reset" value="Reset"> .
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only you can do is to write a javascript function that clear the textarea.

When you use the reset() it only 'return to the state when the page was loaded' this meen that if you make some changes and click on 'Reset' then the textarea will change to the 'old' state.
/Rene
[ July 17, 2002: Message edited by: Rene Larsen ]
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the code below, but it didn't work.
document.View.xmlDocument.value = "";
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I saw it too. You should use 'defaultValue' instead of 'value'

/Rene
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool,it works! Thank you very much!
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rene,
I appricated for your big help. The Jacascript you wrote to validate XML document works. But my application needs to validate special tags format XML document. Could you please advice me? I also want to know how to save the XML document to hard drive. My clients are IE users.
Here is an example (the user can add more tags <command><target> and <requestparameter> :
<?xml version="1.0"?>
<project name="XML Generator Application">
<command name="View">
<codeBase>xmlgenerator.View</codeBase>
<target name="success">text/plain</target>
<target name="fail">/error.jsp</target>
<requestparameter get="true" set="false" name="fileName">java.lang.String</requestparameter>
</command>
</project>
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a new modified version:

I've a question to the XML you should validate - the sample you posted is working - witch part of the XML do not work?
/Rene
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm waiting for your answer while you are waiting my response. Sorry for that. I wish I can express my problem this time. Please help me.
My application needs to validate a given XML document whether it is following the structure as the example file below. The user can't create other tags than those, but they are allowed to add more same tags. This xml file is readed by our servlet framework to parse command name and parameters ect from the front-end pages.
<?xml version="1.0"?>
<project name="XML Generator Application">
<command name="View">
<codeBase>xmlgenerator.View</codeBase>
<target name="success">text/plain</target>
<target name="fail">/error.jsp</target>
<requestparameter get="true" set="false" name="fileName">java.lang.String</requestparameter>
</command>
</project>
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need a 'real' XML validation witch is using a DTD document or XML Schema.
You could let the Servlet implement the validation. I think the parser you are using today can be set to use validation.
/Rene
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familar with DTD. Could you please give me an example code in detail for helping me to start my work? Thanks for your quick response!
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On this link you can get some DTD and Schema tutorials:
http://www.w3schools.com/
/Rene
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and another link:
http://www.zvon.org/o_html/group_xml_newbie.html
/Rene
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read the web sites you pointed to. It helps me to understand the DTD. But I still don't know how to write servlet code to validate XML document by using the DTD. I would appreciate it if you can give me a code example.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read this link http://java.sun.com/webservices/docs/1.0/tutorial/doc/JAXPIntro.html and have downloaded Java XML Pack Summer 02 then you should be able to validate your xml (with the JAXP 1.2 download follow some samples)
/Rene
[ July 19, 2002: Message edited by: Rene Larsen ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!