Solved

JSP and XML

Posted on 2002-07-26
20
285 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to count occurrences of each item in an array.

747 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

10 Experts available now in Live!

Get 1:1 Help Now