Solved

JSP and XML

Posted on 2002-07-26
20
288 Views
Last Modified: 2013-11-19
I wish somebody can advice me how to extract data from the elements and attributes in the given xml document which is validated by the following DTD. I read the examples provided by java.sun.com at http://developer.java.sun.com/developer/technicalArticles/xml/WebAppDev2/, but there is no examples to tell how to extract the data from the attributes of each of the elements.
Here is an DTD for the XML Doc:

<!DOCTYPE project [<!ELEMENT project ( command+) > 
<!ATTLIST project name CDATA #REQUIRED > 
<!ELEMENT command ( codeBase?, target*, requestparameter* ) > 
<!ATTLIST command name NMTOKEN #REQUIRED >
<!ELEMENT codeBase ( #PCDATA ) >
<!ELEMENT target ( #PCDATA ) >
<!ATTLIST target name NMTOKEN #REQUIRED >
<!ELEMENT requestparameter ( #PCDATA ) >
<!ATTLIST requestparameter get ( true | false ) #REQUIRED >
<!ATTLIST requestparameter name NMTOKEN #REQUIRED >
<!ATTLIST requestparameter set ( true | false ) #REQUIRED >
<!ELEMENT sessionattribute ( #PCDATA ) > 
<!ATTLIST sessionattribute get ( true | false ) #REQUIRED >
<!ATTLIST sessionattribute name NMTOKEN #REQUIRED >
<!ATTLIST sessionattribute set ( true | false ) #REQUIRED > ]>

Thanks!

0
Comment
Question by:Amy01
  • 9
  • 7
  • 4
20 Comments
 

Author Comment

by:Amy01
ID: 7180534
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7180556
I think the URL you have does a good job of explaining the process and has sample code, what more are you looking for?

If you want to sidestep the usage of xsl to display the xml you can just use an xml parser to read the xml file and then display the parsed xml in JSP.
0
 

Author Comment

by:Amy01
ID: 7180946
Sorry, this question is waiting to delete before you added your command.
0
 

Author Comment

by:Amy01
ID: 7180954
I have changed my previous question, and make it more clear.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7181106
look at the code on that page that uses the DOMParser, DOM means you have built a tree from the xml document.  you can traverse through the tree and retrieve data.

domstocks.jsp is a good example of how to traverse and display a DOM tree.

CJ
0
 

Author Comment

by:Amy01
ID: 7181133
But the domstocks.jsp doesn't extract data from the attributes. Here is an XML example, and I only need to know each element's name(not value) and it's attributes's names and values.
 
<?xml version="1.0"?>
<project name="XML Generator Application">
     <command name="View">
     <codeBase>xmlgenerator.commands.View</codeBase>
     <target name="success">/viewXMLDocument.jsp</target>
     <target name="fail">/viewXMLDocument.jsp</target>
     <requestparameter get="true" set="false" name="userFile">java.lang.String</requestparameter>
     <requestparameter get="true" set="false" name="action">java.lang.String</requestparameter>
     <requestparameter get="true" set="false" name="xmlDocument">java.lang.String</requestparameter>
     <requestparameter get="true" set="false" name="xmlFile">java.lang.String</requestparameter>
     <requestparameter get="false" set="true" name="msg">java.lang.String</requestparameter>
     <requestparameter get="false" set="true" name="viewList">java.util.Vector</requestparameter>
      </command>
</project>
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7181642
Per request http://www.experts-exchange.com/commspt/Q_20328409.html user resolved the question elsewhere. Points refunded and question closed.

Netminder
CS Moderator
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7182548
I thought the question asker changed the question and was seeking a solution as per their comment on 07/26/2002 01:04PM PST

CJ
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7182617
cheekycj,

If you think you've provided a suitable answer here, let me know and I'll make it right for you. I admit, I missed the asker's comment.

Netminder
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7182637
By NO means have I provided a suitable answer yet, but we were working on it :-)

CJ
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:Netminder
ID: 7183536
Hmmm... well... she asked me to delete it...
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7184082
yeah but then I posted a comment and then she change the question text to start a new thread but lets see what she says and go from there :-)

CJ
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7184100
Okay... you have my email address. I can't remember what the point value was here. Send it, and I'll take care of you.

Netminder
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7188055
I wonder if the question asker is getting email notifs of our posts?  There was an old bug that when a question was closed the question asker did not recieve any more notifs.

CJ
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7188056
I wonder if the question asker is getting email notifs of our posts?  There was an old bug that when a question was closed the question asker did not recieve any more notifs.

CJ
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7188267
I'm receiving them, so I assume the Asker is.

Netminder
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7196111
I don't think the Asker is receiving the notifs.

CJ
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7196513
I'm inclined to agree. Your humble, albeit unquestionably accurate, recommendation, my friend?

N
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7196613
can you email the Asker providing the link to here?  To get her input.

CJ
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7197454
CJ,

You have email.

Netminder
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now