Development Articles
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherDevelopment Articles

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 June 22nd, 2004, 08:26 AM
Admin Admin is offline
Developer Shed
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Posts: 961 Admin User rank is Sergeant Major (2000 - 5000 Reputation Level)Admin User rank is Sergeant Major (2000 - 5000 Reputation Level)Admin User rank is Sergeant Major (2000 - 5000 Reputation Level)Admin User rank is Sergeant Major (2000 - 5000 Reputation Level)Admin User rank is Sergeant Major (2000 - 5000 Reputation Level)Admin User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old June 23rd, 2004, 03:38 AM
neutcomp neutcomp is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: The Netherlands
Posts: 10 neutcomp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to neutcomp
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

Reply With Quote
  #3  
Old June 23rd, 2004, 09:24 AM
jaimz jaimz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 23 jaimz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 10 sec
Reputation Power: 0
you have to have php5 for it to work

Reply With Quote
  #4  
Old June 23rd, 2004, 09:25 PM
Caged Caged is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 Caged User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #5  
Old June 24th, 2004, 01:20 AM
jaimz jaimz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 23 jaimz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 10 sec
Reputation Power: 0
what does your XML file look like?

do you have

<?xml version="1.0" encoding="UTF-8" ?>

at the top of your xml file?

Reply With Quote
  #6  
Old June 24th, 2004, 03:40 PM
Caged Caged is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 Caged User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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:
<?php
 
//error_reporting(E_ALL);
 
$tpl simplexml_load_file('template.xml');
 
print_r($tpl);
 
?>


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.

Reply With Quote
  #7  
Old July 22nd, 2004, 04:38 PM
Helios Helios is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: Chicago, USA
Posts: 73 Helios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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.

Reply With Quote
  #8  
Old July 26th, 2004, 03:34 AM
dejaone dejaone is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 300 dejaone User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m 22 sec
Reputation Power: 5
very useful introduction for doing XML in php.

Reply With Quote
  #9  
Old September 21st, 2004, 09:00 AM
papalangi papalangi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 papalangi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #10  
Old February 15th, 2007, 03:21 AM
damtrojan damtrojan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 1 damtrojan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 48 sec
Reputation Power: 0
Thumbs up

Quote:
Originally Posted by papalangi
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.



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:"

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherDevelopment Articles > Article Discussion: SimpleXML


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



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





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