10 JSP vs PHP offer xml JSP offers

  • Slides: 8
Download presentation
Μάθημα 10 JSP vs PHP

Μάθημα 10 JSP vs PHP

offer. xml JSP offers (model) <? xml version="1. 0" encoding="UTF-8"? > <offer> < header>50%

offer. xml JSP offers (model) <? xml version="1. 0" encoding="UTF-8"? > <offer> < header>50% Discount on rooms</header> <body> Today all rooms 50% down</body> < /offer> </xml> Η σελίδα offers. jsp <%@ page content. Type="text/html; charset=utf-8" language="java" import="javax. xml. parsers. Document. Builder. Factory, javax. xml. parsers. Document. Builder, org. w 3 c. dom. *" error. Page="" %> <% Document. Builder. Factory dbf = Document. Builder. Factory. new. Instance(); Document. Builder db = dbf. new. Document. Builder(); Document doc = db. parse(“offer. xml"); Node. List header = doc. get. Elements. By. Tag. Name(“header"); Node. List body = doc. get. Elements. By. Tag. Name(“body"); %>

JSP offers (view) <html> <p>OFFERS</p> <table border="1"> <% int i; for(i=0; i<=header. get. Length()-1;

JSP offers (view) <html> <p>OFFERS</p> <table border="1"> <% int i; for(i=0; i<=header. get. Length()-1; i++) { %> <tr><td> <b> <%= header. item(i). get. First. Child(). get. Node. Value()%> </b> </td></tr> <tr><td> <%= body. item(i). get. First. Child(). get. Node. Value()%> </td></tr> <% } %> </table> </body> </html>

PHP XML-DOM offer. xml <? xml version="1. 0" encoding="UTF-8"? > <offer> < header>50% Discount

PHP XML-DOM offer. xml <? xml version="1. 0" encoding="UTF-8"? > <offer> < header>50% Discount on rooms</header> <body> Today all rooms 50% down</body> < /offer> <? php $xml. Doc = new DOMDocument(); $xml. Doc->load(“offer. xml"); $x = $xml. Doc->document. Element; ? > <? php print “<html><p>OFFERS</p><Table>” foreach ($x->child. Nodes AS $item) { print “<tr><td>". $item-> node. Value. “</td></tr>"; } print “</table></html>” ? >