{"id":1392,"date":"2018-01-19T19:22:47","date_gmt":"2018-01-19T19:22:47","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/dynamic-xml-conversion-using-the-sax-parser\/"},"modified":"2018-01-19T19:24:45","modified_gmt":"2018-01-19T19:24:45","slug":"dynamic-xml-conversion-using-the-sax-parser","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/dynamic-xml-conversion-using-the-sax-parser\/","title":{"rendered":"Dynamic XML Conversion Using the SAX Parser"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By PHP Builder Staff<\/div>\n<div class=\"\">on April 28, 2003<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<div class=\"articlePara\">\nThis article describes an alternative way of converting XML to HTML using the SAX parser.<br \/>\nFor each tag you want to convert, you write a conversion function. This function is called<br \/>\nwith two arguments: contents and attributes. The return value of the function will replace<br \/>\nthe tag and its contents in the finished document. <\/div>\n<h2>Introduction<\/h2>\n<div class=\"articlePara\">\nWe all know it: XML is great. (If you don&#8217;t, look at some of the great articles at this site.)<br \/>\nBut why is it so complicated to use?  You have to learn about DTDs, XSLTs, DOM, XPATH, XPOINTER&#8230;<br \/>\nthis is a lot of work, and most of these techniques are not really neccessary to build a website. <\/div>\n<div class=\"articlePara\">\nIn this article you will learn how to build a simple converter for your XML.<\/div>\n<div class=\"articlePara\">\nThe idea is this: You have a web page in clean XHTML. The biggest part of the html will be<br \/>\ntables, menu images and other design stuff. So why not replace the 30 kilobyte code for the<br \/>\nmenu with a nice little &#8220;&lt;menu \/&gt;&#8221;? <\/div>\n<div class=\"articlePara\">\nWhen the document is opened from a webserver, a small php script replaces the &lt;menu \/&gt;-tag with<br \/>\nthe correct table HTML. So you have a much cleaner document, and the end result is the same. You<br \/>\ncan compose your whole page using these meta-tags, and even dynamic tags like &lt;uppercase&gt; or<br \/>\n&lt;showdate \/&gt; are easy to program.<\/div>\n<div class=\"articlePara\">\nThese are the steps we will take:<\/div>\n<div class=\"articlePara\">\nThink up a set of tags that can be used to build an example website. <\/div>\n<div class=\"articleList\">\n<ul>\n<li>Write functions that convert these tags into HTML.<\/li>\n<li>Write a script that takes input from the SAX XML parser and calls the conversion functions with the required arguments<\/li>\n<li>Send the output of these functions to the browser<\/li>\n<\/ul>\n<\/div>\n<div class=\"articlePara\">\nWe will use the SAX parser to build the converter. To learn more about SAX and EXPAT<br \/>\n(which is the name of the SAX implementation that PHP uses), please read Justin Grant&#8217;s article<br \/>\n&#8220;<a href=\"justin20000428.html\" target=\"_blank\">PHP and XML: using<br \/>\nexpat functions<\/a>&#8220;.\n<\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">1<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"scheffler200303254658.html?page=2\">2<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"scheffler200303259ba9.html?page=3\">3<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"scheffler20030325fdb0.html?page=4\">4<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"scheffler20030325af4d.html?page=5\">5<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"scheffler20030325c575.html?page=6\">6<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"scheffler20030325235c.html?page=7\">7<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"scheffler200303254658.html?page=2\">Next Page \u00bb<\/a><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This article describes an alternative way of converting XML to HTML using the SAX parser. For each tag you<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1392","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1392"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1392\/revisions"}],"predecessor-version":[{"id":3262,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1392\/revisions\/3262"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}