XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 10th, 2004, 11:46 AM
bannyjean bannyjean is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Massachusetts
Posts: 15 bannyjean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to bannyjean
Loop through XML elements using HTML ONLY

Hello,
I am having difficulty finding help on this topic, as most people use XSL to display the tags (which is understandable). However, I am trying to minimize my work here and just display the XML elements in HTML. At this point, I am only able to display the first set of tags, so I need a means of looping through the rest of the xml file. Any ideas, anyone??

XML:
<?xml version= "1.0" ?>

<Research>
<coral>
<Family>Xeniidae</Family>
<CommonName>Pumping Xenia</CommonName>
<Light>Medium</Light>
<Flow>Medium</Flow>
<Care>Moderate</Care>
</coral>
<coral>
<Family>Zoanthidae</Family>
<CommonName>Colony Polyp</CommonName>
<Light>Medium</Light>
<Flow>Medium</Flow>
<Care>Easy</Care>
</coral>
</Research

HTML:
<html>
<head>
<title>Fast, Accurate Research on Corals</title>
</head>

<body>
<xml src="ResearchCorals.xml" id="refTable"></xml>

<table border="1" style="font: 10pt Verdana, sans-serif;
color:navy; background-color:rgb(255,255,200)"
cellpadding="5" >
<thead>
<td>Family</td>
<td>Light</td>
<td>Water Flow</td>
<td>Care Level</td>
</thead>
<td>
<span datasrc="#refTable"
datafld="Family"></span>
</td>
<td>
<span datasrc="#refTable"
datafld="Light"></span>
</td>
<td>
<span datasrc="#refTable"
datafld="Flow"></span>
</td>
<td>
<span datasrc="#refTable"
datafld="Care"></span>
</td>
</tr>
</table>

</body>
</html>


THANKS FOR THE HELP!!

Reply With Quote
  #2  
Old May 10th, 2004, 12:48 PM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 6
Hmm... I would think XSL would be the easiest method.

Code:
<xsl:for-each select="Research/coral">

<xsl:value-of select="whatever you want here" />


</xsl:for-each>
__________________
Hello, old friend...

Reply With Quote
  #3  
Old May 10th, 2004, 04:49 PM
bannyjean bannyjean is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Massachusetts
Posts: 15 bannyjean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to bannyjean
Thanks khwang, but I seemed to have figured it out without using xsl.
Here are the changes I made in the html file:
<table border="1" style="font: 10pt Verdana, sans-serif;
color:navy; background-color:rgb(102, 102, 255)"
cellpadding="5" datasrc="#refTable" align="center">

<td>
<span datafld="Family" ></span>
</td>

Thanks again! I appreciate the effort!!

Reply With Quote
  #4  
Old May 24th, 2004, 05:02 AM
oelafi oelafi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 2 oelafi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hi man you can use this cod to loop in xml file



import java.io.File;
import org.w3c.dom.Document;
import org.w3c.dom.*;


import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class ReadAndPrintXMLFiles{


public static void main (String argv []){
try {


DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File("book.xml"));

// normalize text representation
doc.getDocumentElement ().normalize ();
System.out.println ("Root element of the doc is " + doc.getDocumentElement().getNodeName());


NodeList listOfPersons = doc.getElementsByTagName("person");
int totalPersons = listOfPersons.getLength();
System.out.println("Total no of people : " + totalPersons);
for(int s=0; s<listOfPersons.getLength() ; s++){


Node firstPersonNode = listOfPersons.item(s);
if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){


Element firstPersonElement = (Element)firstPersonNode;

//-------
NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
Element firstNameElement = (Element)firstNameList.item(0);

NodeList textFNList = firstNameElement.getChildNodes();
System.out.println("First Name : " + ((Node)textFNList.item(0)).getNodeValue().trim());

//-------
NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
Element lastNameElement = (Element)lastNameList.item(0);

NodeList textLNList = lastNameElement.getChildNodes();
System.out.println("Last Name : " + ((Node)textLNList.item(0)).getNodeValue().trim());

//----
NodeList ageList = firstPersonElement.getElementsByTagName("age");
Element ageElement = (Element)ageList.item(0);

NodeList textAgeList = ageElement.getChildNodes();
System.out.println("Age : " + ((Node)textAgeList.item(0)).getNodeValue().trim());

//------


}//end of if clause


}//end of for loop with s var


}catch (SAXParseException err) {
System.out.println ("** Parsing error" + ", line " + err.getLineNumber () + ", uri " + err.getSystemId ());
System.out.println(" " + err.getMessage ());

}catch (SAXException e) {
Exception x = e.getException ();
((x == null) ? e : x).printStackTrace ();

}catch (Throwable t) {
t.printStackTrace ();
}
//System.exit (0);

}//end of main


}





see the xml file it work with java cod


<?xml version="1.0"?>
<book>
<person>
<first>Otman</first>
<last>Elafi</last>
<age>32</age>
</person>

<person>
<first>Amal</first>
<last>Elfituri</last>
<age>23</age>
</person>

<person>
<first>Tasneem</first>
<last>Elafi</last>
<age>2</age>
</person>

<person>
<first>Kiran</first>
<last>Pai</last>
<age>22</age>
</person>

<person>
<first>Bill</first>
<last>Gates</last>
<age>46</age>
</person>

<person>
<first>Steve</first>
<last>Jobs</last>
<age>40</age>
</person>
</book>

Reply With Quote
  #5  
Old May 24th, 2004, 06:23 AM
NickNet NickNet is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 97 NickNet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 21 m 53 sec
Reputation Power: 5
Quote:
Originally Posted by khwang
Hmm... I would think XSL would be the easiest method.

Code:
<xsl:for-each select="Research/coral">

<xsl:value-of select="whatever you want here" />


</xsl:for-each>



Ah...........I agree with khwang.
You really want to invent another one?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Loop through XML elements using HTML ONLY


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT