|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Article Discussion: SimpleXML
Learn an easy way to parse XML and putput it the way you want by using the simpleXML extensions in PHP5. Murray outlines the 3 main elements of an XML document and how to replace them with your own non-template data and how to build an array of all the tags put in the document.
Read the full article here: SimpleXML |
|
#2
|
|||
|
|||
|
Nice but cant get it to work!
Hello,
nice article but I dont really get it to work. What i have now in my index.php Code:
<?
include("parser.php");
$template = new template();
$template->xml_path = "";
$template->xml_file="template.xml";
$template->load();
$template->add_elem("header","header");
$template->add_elem("body","body");
$template->add_elem("footer","footer");
$template->add_tags("title","This is the simpleXML test page");
$template->add_tags("logo","simpleXML is simple!");
$template->add_tags("column1","This is column one");
$template->add_tags("column2","This is column two");
$template->add_tags("column3","This is column three");
$template->add_tags("footer","this is the footer information");
echo $template->parse_elem();
?>
The parser.php and template.xml are just copy past from your tutorial and are in the same directory as index.php Hope you can help me out. thanxx Bjorn PHP Version 4.3.1 IIS |
|
#3
|
|||
|
|||
|
you have to have php5 for it to work
|
|
#4
|
|||
|
|||
|
I am getting a few errors myself that I can't seem to figure out. I'm not sure if its the whitespace causing it or what but the xml file will not parse.
I created another xml file with a simple xml file and it works, but when I start adding html tags, etc I recieve errors like: Code:
Warning: template2.xml:23: error: Input is not proper UTF-8, indicate encoding ! in d:\wamp\www\xml\index.php on line 3 Warning: in d:\wamp\www\xml\index.php on line 3 Warning: ^ in d:\wamp\www\xml\index.php on line 3 Warning: template2.xml:23: error: Bytes: 0x94 0x31 0x35 0x25 in d:\wamp\www\xml\index.php on line 3 Warning: in d:\wamp\www\xml\index.php on line 3 Warning: ^ in d:\wamp\www\xml\index.php on line 3 I'm using Php 5 RC3 |
|
#5
|
|||
|
|||
|
what does your XML file look like?
do you have <?xml version="1.0" encoding="UTF-8" ?> at the top of your xml file? |
|
#6
|
|||
|
|||
|
The contents of my xml file:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<template>
<header>
<![CDATA[
<html>
<head>
<title>Testing Xml</title>
<style type="text/css">
div {
border: 1px solid #333333;
}
</style>
</head>
<body>
<div style="width:100px;">My Header</div>
]]>
</header>
<content>
<![CDATA[
<div style="height:400px;">This is My Body</div>
]]>
</content>
<footer>
<![CDATA
<div style="height:50px;">My Footer</div>
</body>
</html>
]]>
</footer>
</template>
And my php remains simple until I can isolated the problem PHP Code:
I am gonna take a stab at it again and see if it might be a whitespace issue, but as of yet I haven't found anything on simpleXml and whitespace. Update: Ok, I've gotten it to work to some extent. This will parse just fine: Code:
<?xml version="1.0" encoding="UTF-8" ?> <template> <header> <![CDATA[ <html> <head> <title>Testing</title> </head> <body> <div style="text-align:center;"> Testing Whitepspace</div> ]]> </header> <footer> <![CDATA[ <div>Footer</div> </body> </html> ]]> </footer> </template> But assuming I copy and paste what the article states, the errors start pouring in, even though I've checked the syntax and everything seems to be ok, It still results in an error. |
|
#7
|
|||
|
|||
|
your article was a nice intro. to simplexml and template logic but I have to say the grammer and number of typos left a bad taste. devshed usually has pretty good articles and I would think they are trying to maintain some sort of standard. a thorough proof-read or two certainly wouldn't hurt especially when you are getting paid for your work.
|
|
#8
|
|||
|
|||
|
very useful introduction for doing XML in php.
__________________
Wedding Gifts | Web Development | Order Fulfllment | Supply Chain | E-Business | Add to 100 SEO Friendly Directories fast do it yourself |
|
#9
|
|||
|
|||
|
Got the same errors
Could be a very usefull arcticle. But i got the same Errors,
This is is annoying. The reason for the Errors are the strange quotes in <td width=”15%”><!column1></td> Also the include for the parser.php was missing. As a beginner in php and xml this is confusing. The remaing article is complete and helpfull. |
|
#10
|
|||
|
|||
|
Quote:
Not sure if anyone knows abou this but I quote:"Input is not proper UTF-8, indicate encoding ! Now that you know this fails, you can try using an XML declaration, as demonstrated in Listing 5-2, but still not specify encoding. This will at least give libxml2 a chance to try to autodetect the encoding used. Listing 5-2. XML Document with French and XML Declaration but No Encoding <?xml version="1.0"?> <doc> <élément>contenu d'élément</élément> </doc> This isn’t surprising—the parser encounters the same error. The parser detected the XML declaration but detected it as UTF-8. So, the parser used the same encoding regardless of whether you specified the XML declaration. If you saved the document in Listing 5-2 as a file in UTF-16 format, the autodetection would have at least noticed this and tried loading it using UTF-16 as the encoding. For the last try to get this document to load properly, set the encoding attribute on the XML declaration, as illustrated in Listing 5-3. Listing 5-3. XML Document with French and Encoding Specified <?xml version="1.0" encoding="ISO-8859-1"?> <doc> <élément>contenu d'élément</élément> </doc> This time it finally loads without an error. The encoding you needed in this case was ISO-8859-1, which allows the use of the French characters within the document. If you now instructed the parser to dump the document to the standard console, you might not expect to see what it outputs:" |
![]() |
| Viewing: Dev Shed Forums > Other > Development Articles > Article Discussion: SimpleXML |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|