www.webdeveloper.com
Results 1 to 10 of 10

Thread: XML and XHTML help required please guys!

  1. #1
    Join Date
    Apr 2010
    Posts
    1

    Thumbs up XML and XHTML help required please guys!

    I have the following question for my research. I don't know how to do it, any hints would be gratefully received.

    Given the following XML extract all of the name and ages of the students and create an XHTML table.

    <CLASS ID="Advanced Web Development">
    <STUDENT>
    <NAME>Tom</NAME>
    <AGE>19</AGE>
    <HEIGHT>1.3</HEIGHT>
    <SEX>M</SEX>
    <GRADE>B</GRADE>
    </STUDENT>
    <STUDENT>
    <NAME>Dick</NAME>
    <AGE>29</AGE>
    <HEIGHT>1.1</HEIGHT>
    <SEX>M</SEX>
    <GRADE>A</GRADE>
    </STUDENT>
    <STUDENT>
    <NAME>Harry</NAME>
    <AGE>39</AGE>
    <HEIGHT>1.5</HEIGHT>
    <SEX>M</SEX>
    <GRADE>C</GRADE>
    </STUDENT>
    <STUDENT>
    <NAME>Mary</NAME>
    <AGE>30</AGE>
    <HEIGHT>1.1</HEIGHT>
    <SEX>F</SEX>
    <GRADE>B+</GRADE>
    </STUDENT>

  2. #2
    Join Date
    Apr 2010
    Location
    USA
    Posts
    55
    For every XML format ! There is a need of XML supported Program reader . OR simply we say XML reader.
    Developers simply do is they made a XML reader generic and after that they pick up the data. And obviously XML is a way to transmit data over the internet !

    You can create XML reader technology dependent ! or language dependent ! Once i made XML reader in Asp.net Application using C# !
    You can take help from the Microsoft official website if you want to developed it using asp.net !

    Another term is used to extract the data from XML is XML PARSER !

    Regards

  3. #3
    Join Date
    Mar 2010
    Location
    Singapore
    Posts
    367
    Quote Originally Posted by andrewdavid View Post
    Another term is used to extract the data from XML is XML PARSER !
    Regards
    In recent times there have been feedback from certain developer community about XML format. They are just too verbose and the number of bytes needed to transfer from server to client multiples very quick when the traffic get heavy.

    An alternative format called JSON is proposed which greatly reduce the number of bytes for transfer. Any Ajax developers would know of this format called JSON. Both client and server end need a JSON parser instead of XML parser.

    As to will JSON survive longer than XML I do not know but it does have some merits in my opinion.

  4. #4
    Join Date
    Jan 2010
    Location
    Germany
    Posts
    10
    there a many Parsers which can use to build an xhtml file

    look here xslt processors
    there also explain and how use and install


    and you make a xslt file to modify xml to xthml

    my file
    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="xml" encoding="UTF-8" indent="yes" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" doctype-public="-//W3C//DTD XHTML 1.1//EN"/>
    	<xsl:template match="/">
    		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    			<head>
    				<title>Students <xsl:value-of select="CLASS/@ID"/></title>
    				<style type="text/css">
    table
    {
    border-collapse:collapse;
    width:100&#37;;
    }
    table,th, td
    {
    border: 2px solid black;
    padding:15px;
    text-align:center;
    }</style>
    			</head>
    			<body>
    				<xsl:apply-templates select="CLASS"/>
    				<p>
    					<a href="http://validator.w3.org/check?uri=referer">
    						<img src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid XHTML 1.1" height="31" width="88"/>
    					</a>
    				</p>
    			</body>
    		</html>
    	</xsl:template>
    	<xsl:template match="CLASS">
    		<table>
    			<caption>
    				<xsl:value-of select="@ID"/>
    			</caption>
    			<thead>
    
    				<tr>
    					<th>Name</th>
    					<th>Age</th>
    				</tr>
    			</thead>
    			<xsl:apply-templates select="STUDENT"/>
    		</table>
    	</xsl:template>
    
    	<xsl:template match="STUDENT">
    		<tbody>
    			<tr>
    				<td>
    					<xsl:value-of select="NAME"/>
    				</td>
    				<td>
    					<xsl:value-of select="AGE"/>
    				</td>
    			</tr>
    		</tbody>
    	</xsl:template>
    </xsl:stylesheet>
    result
    Code:
    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>Students Advanced Web Development</title>
        <style type="text/css">
    table
    {
    border-collapse:collapse;
    width:100%;
    }
    table,th, td
    {
    border: 2px solid black;
    padding:15px;
    text-align:center;
    }
        </style>
      </head>
      <body>
        <table>
          <caption>Advanced Web Development</caption>
          <thead>
            <tr>
              <th>Name</th>
              <th>Age</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>Tom</td>
              <td>19</td>
            </tr>
          </tbody>
          <tbody>
            <tr>
              <td>Dick</td>
              <td>29</td>
            </tr>
          </tbody>
          <tbody>
            <tr>
              <td>Harry</td>
              <td>39</td>
            </tr>
          </tbody>
          <tbody>
            <tr>
              <td>Mary</td>
              <td>30</td>
            </tr>
          </tbody>
        </table>
        <p>
          <a href="http://validator.w3.org/check?uri=referer">
            <img src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid XHTML 1.1" height="31" width="88"/>
          </a>
        </p>
      </body>
    </html>
    to controlle your xhtml file use
    validator from w3.org

  5. #5
    Join Date
    May 2010
    Posts
    2
    Hi!

    Following on from the original post, I used the advice above to do a similar question but I have an additional query.

    How do I extract and display in a table only those who have achieved an A grade?

    Thanks so much! Any help is much appreciated.

  6. #6
    Join Date
    Mar 2010
    Location
    Singapore
    Posts
    367
    Quote Originally Posted by jpeterman View Post
    Hi!
    Following on from the original post, I used the advice above to do a similar question but I have an additional query.

    How do I extract and display in a table only those who have achieved an A grade?

    Thanks so much! Any help is much appreciated.
    You want to perform a query on the XML input data correct? You may want to consider using a more recent technology called XQuery which literally means SQL for XML. It come with some features on performing transformation like XSLT too.

    But if XQuery cannot be used, I can't help you there. Hope some XSLT guys in this forum can help.

  7. #7
    Join Date
    May 2010
    Posts
    2
    Thanks for your reply! I can't imagine its that hard, I'm only in first year and it's an XSLT exercise so I don't think XQuery can be used.

    I just need to find a way of only displaying those who got an A grade.

    I have them all displayed currently, but can't get the 'A grade' condition working!

    I'm a total novice at this as you can tell.

  8. #8
    Join Date
    Jan 2010
    Location
    Germany
    Posts
    10
    at first
    xml is a tree of datastructur
    beginns with the root
    in root will be descript the document
    eg <?xml version="1.0" encoding="ISO8859-1"?>

    then becomes your the data

    <CLASS ID="Advanced Web Development">
    <STUDENT>
    <NAME>Tom</NAME>
    <AGE>19</AGE>
    <HEIGHT>1.3</HEIGHT>
    <SEX>M</SEX>
    <GRADE>B</GRADE>
    </STUDENT>

    in <xsl:template match="/">
    you will define the root template alle xml docment have this node

    in this template you can controlle which is next node will be connect
    with
    <xsl:apply-templates select="CLASS"/>


    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="xml" encoding="UTF-8" indent="yes" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" doctype-public="-//W3C//DTD XHTML 1.1//EN"/>
    	<xsl:template match="/">
    		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    			<head>
    				<title>Students <xsl:value-of select="CLASS/@ID"/></title>
    				<style type="text/css">
    table
    {
    border-collapse:collapse;
    width:100%;
    }
    table,th, td
    {
    border: 2px solid black;
    padding:15px;
    text-align:center;
    }
    th
    {
    background-color:yellow;
    }
    #even
    {
    background-color:#ff0000
    }
    #odd
    {
    background-color:#00FF00
    }
    </style>
    			</head>
    			<body>
    				<xsl:apply-templates select="CLASS"/>
    				<p>
    					<a href="http://validator.w3.org/check?uri=referer">
    						<img src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid XHTML 1.1" height="31" width="88"/>
    					</a>
    				</p>
    			</body>
    		</html>
    	</xsl:template>
    	<xsl:template match="CLASS">
    		<table>
    			<caption>
    				<xsl:value-of select="@ID"/>
    			</caption>
    			<thead>
    				<tr>
    					<th>Pos</th>
    					<th>Name</th>
    					<th>Age</th>
    					<th>Grade</th>
    				</tr>
    			</thead>
    			<xsl:apply-templates select="STUDENT"/>
    		</table>
    	</xsl:template>
    
    	<xsl:template match="STUDENT">
    		<tbody>
    			<tr>
    				<xsl:choose>
    					<xsl:when test="position() mod 2 = 1">
    						<xsl:attribute name="id">odd</xsl:attribute>
    					</xsl:when>
    					<xsl:otherwise>
    						<xsl:attribute name="id">even</xsl:attribute>
    					</xsl:otherwise>
    				</xsl:choose>
    				<td>
    					<xsl:value-of select="position()"/>
    				</td>
    				<td>
    					<xsl:value-of select="NAME"/>
    				</td>
    				<td>
    					<xsl:value-of select="AGE"/>
    				</td>
    				<td>
    					<xsl:value-of select="GRADE"/>
    				</td>
    			</tr>
    		</tbody>
    	</xsl:template>
    </xsl:stylesheet>
    Code:
    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>Students Advanced Web Development</title>
        <style type="text/css">table
    {
    border-collapse:collapse;
    width:100%;
    }
    table,th, td
    {
    border: 2px solid black;
    padding:15px;
    text-align:center;
    }
    th
    {
    background-color:yellow;
    }
    #even
    {
    background-color:#ff0000
    }
    #odd
    {
    background-color:#00FF00
    }
    
    
        </style>
      </head>
      <body>
        <table>
          <caption>Advanced Web Development</caption>
          <thead>
            <tr>
              <th>Pos</th>
              <th>Name</th>
              <th>Age</th>
              <th>Grade</th>
            </tr>
          </thead>
          <tbody>
            <tr id="odd">
              <td>1</td>
              <td>Tom</td>
              <td>19</td>
              <td>B</td>
            </tr>
          </tbody>
          <tbody>
            <tr id="even">
              <td>2</td>
              <td>Dick</td>
              <td>29</td>
              <td>A</td>
            </tr>
          </tbody>
          <tbody>
            <tr id="odd">
              <td>3</td>
              <td>Harry</td>
              <td>39</td>
              <td>C</td>
            </tr>
          </tbody>
          <tbody>
            <tr id="even">
              <td>4</td>
              <td>Mary</td>
              <td>30</td>
              <td>B+</td>
            </tr>
          </tbody>
        </table>
        <p>
          <a href="http://validator.w3.org/check?uri=referer">
            <img src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid XHTML 1.1" height="31" width="88"/>
          </a>
        </p>
      </body>
    </html>
    you can also use xquery

  9. #9
    Join Date
    Jan 2010
    Location
    Germany
    Posts
    10
    I use datadirect xquery parser

    little example


    Code:
    declare option ddtek:serialize "indent=yes, omit-xml-declaration=no, encoding=ISO-8859-1";
    <html >
    				
    {
    	for $p in //CLASS
    	return 
    	<table>
    	<tr><th>Name</th><th>Age</th><th>Grade</th></tr>
    	{
    		for $dat in $p/STUDENT
    		return <tr><td>{data($dat/NAME)}</td> <td>{data($dat/AGE)}</td><td>{data($dat/GRADE)}</td></tr>
    	}
    	</table> 
    }
    </html>

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <html>
    	<table>
    		<tr>
    			<th>Name</th>
    			<th>Age</th>
    			<th>Grade</th>
    		</tr>
    		<tr>
    			<td>Tom</td>
    			<td>19</td>
    			<td>B</td>
    		</tr>
    		<tr>
    			<td>Dick</td>
    			<td>29</td>
    			<td>A</td>
    		</tr>
    		<tr>
    			<td>Harry</td>
    			<td>39</td>
    			<td>C</td>
    		</tr>
    		<tr>
    			<td>Mary</td>
    			<td>30</td>
    			<td>B+</td>
    		</tr>
    	</table>
    </html>

  10. #10
    Join Date
    Mar 2010
    Location
    Singapore
    Posts
    367
    Quote Originally Posted by xml-looser View Post
    I use datadirect xquery parser
    little example
    I don't think DataDirect XQuery parser is free. Me did a internet search awhile back and based on huge XML file input, it seem certain XQuery parsers are better performance. Saxon is good but I don't like it's license terms so ambiguous. MXQuery vs BaseX and I would give the thumbs up to BaseX which is from a department in a German University. BaseX offers more than just a XQuery parser, in fact it provide a pure XML ground-up database which is a huge under-taking in my opinion.

    http://www.w3.org/2005/qt-applets/xqueryApplet.html

    Just found out above URL has a Java applet that can help you to parse XQuery statement cool. Aha.... Java applet technology is not dead and buried after all
    Last edited by sohguanh; 05-11-2010 at 02:40 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles