PHP not creating well-formed XML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

PHP not creating well-formed XML

Post by jwalsh »

Hi,

I'm using the following code to generate an XML file, but I keep getting the following warning. I'm not sure what the problem is, perhaps it's getting confused because of the = sign, but it gets past the one after "module" just fine. I tried using ≡ but that didn't work either.

Thanks,

Code: Select all

XML Parsing Error: not well-formed
Location: http://www.realitygrp.com/xml.php?mode=links
Line Number 3, Column 64:
	<link name=">Current Events" ref="home.php?module=Category&cat=37"/>
-----------------------------------------------------------------^
Here's the full output.

Code: Select all

<links name="FEATURED CHANNELS">
	<link name=">Link 1" ref="home.php?module=Category&cat=37"/>
	<link name=">Link 2" ref="home.php?module=Category&cat=38"/>
	<link name=">Link 3" ref="home.php?module=Category&cat=39"/>
	<link name=">Link 4" ref="home.php?module=Category&cat=40"/>
	<link name=">Link 5" ref="home.php?module=Category&cat=41"/>
	<link name=">Link 6" ref="home.php?module=Category&cat=42"/>
</links>
And, this probably doesn't matter, but here's the PHP that generates it.

Code: Select all

echo "<links name=\"FEATURED CHANNELS\">\n";
		
		// LOOP
		$CATS = new DB;
		$CATS->query("SELECT id FROM category WHERE parentid = 0 ORDER BY id");
		
		// IF WE'RE ON A SUB NAV, GET THE TOP LEVEL CATEGORY
		$TOPCAT = $THISCATEGORY->parent_path[1];
		
		foreach ($CATS->all_rows AS $category) {
			$NAVIGATION = new Category;
			$NAVIGATION->GetById($category['id']);
			echo "\t<link name=\">{$NAVIGATION->title}\" ref=\"home.php?module=Category&cat={$NAVIGATION->id}\"/>\n";
		}
		
		echo "</links>\n";
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

it's not = it's the & that's breaking your string. Replace it with & and you'll be fine

Code: Select all

<links name="FEATURED CHANNELS">
   <link name=">Link 1" ref="home.php?module=Category&cat=37"/>
   <link name=">Link 2" ref="home.php?module=Category&cat=38"/>
   <link name=">Link 3" ref="home.php?module=Category&cat=39"/>
   <link name=">Link 4" ref="home.php?module=Category&cat=40"/>
   <link name=">Link 5" ref="home.php?module=Category&cat=41"/>
   <link name=">Link 6" ref="home.php?module=Category&cat=42"/>
</links>
here's some reading http://www.ftponline.com/vsm/2002_11/on ... _11_05_02/
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Code: Select all

<links name="FEATURED CHANNELS"> 
   <link name=">Link 1" ref="home.php?module=Category&cat=37"/> 
   <link name=">Link 2" ref="home.php?module=Category&cat=38"/> 
   <link name=">Link 3" ref="home.php?module=Category&cat=39"/> 
   <link name=">Link 4" ref="home.php?module=Category&cat=40"/> 
   <link name=">Link 5" ref="home.php?module=Category&cat=41"/> 
   <link name=">Link 6" ref="home.php?module=Category&cat=42"/> 
</links>
This does not look like XML itself. You have double quotes at wrong places.
are you trying to create XML attributes or just want to put values in.

YOu start with <link> then you should finish with </link>
else you should put it as <link />

Further examining, I found out this, you have an additional ">" operator. Your code should be...

Code: Select all

echo "\t<link name=\"{$NAVIGATION->title}\" ref=\"home.php?module=Category&cat={$NAVIGATION->id}\"&nbsp;/>\n";
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Out of curiosity, jwalsh, are you planning to work for the phpbb team in the future?
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post by jwalsh »

foobar,

Haha, I know what you mean. This project is exactly that, just experimenting with a few different modular systems... I like how segregated the code is, but there are other things I don't like.

FYI, I don't think I have an extra >, that's used as a bullet next to the link, and is inside quotes, shouldn't matter... I dont think :)

Thanks for the XML tips, I'll take a look in a few hours when I get home.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

jwalsh wrote:FYI, I don't think I have an extra >, that's used as a bullet next to the link, and is inside quotes, shouldn't matter... I dont think :)
It does matter in XML - you need to encode it -so < should do it.

Mac
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

twigletmac wrote:
jwalsh wrote:FYI, I don't think I have an extra >, that's used as a bullet next to the link, and is inside quotes, shouldn't matter... I dont think :)
It does matter in XML - you need to encode it -so < should do it.

Mac
If I am not totally wrong, I think that is a greater than symbol, should be replaced by >
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

raghavan20 wrote:
twigletmac wrote:
jwalsh wrote:FYI, I don't think I have an extra >, that's used as a bullet next to the link, and is inside quotes, shouldn't matter... I dont think :)
It does matter in XML - you need to encode it -so < should do it.

Mac
If I am not totally wrong, I think that is a greater than symbol, should be replaced by >
Oops read it wrong, nevermind.

Mac
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post by jwalsh »

Works great. I love you guys!
Post Reply