Page 1 of 1

PHP not creating well-formed XML

Posted: Tue Jan 17, 2006 9:23 pm
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";

Posted: Wed Jan 18, 2006 1:10 am
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/

Posted: Wed Jan 18, 2006 2:38 am
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";

Posted: Wed Jan 18, 2006 3:23 am
by foobar
Out of curiosity, jwalsh, are you planning to work for the phpbb team in the future?

Posted: Wed Jan 18, 2006 7:24 am
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.

Posted: Wed Jan 18, 2006 9:45 am
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

Posted: Wed Jan 18, 2006 10:36 am
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 >

Posted: Wed Jan 18, 2006 10:38 am
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

Posted: Wed Jan 18, 2006 12:10 pm
by jwalsh
Works great. I love you guys!