/    Sign up×
Community /Pin to ProfileBookmark

PHP causing XML Parsing Error

Okay, so I created a php file that was supposed to create an XML file which would later be used in an AJAX call. However I get this error when I try to look at the XML:

[CODE]XML Parsing Error: not well-formed
Location: http://bellevue.com/includes/getByCategory.php
Line Number 1, Column 121:<?xml version=”1.0″ encoding=”UTF-8″?><markers><marker lat=”43.65654″ lng=”-79.90138″ html=”Some stuff to display in the<br>First Info Window” label=”Test” /></markers>
————————————————————————————————————————^[/CODE]

You can check the error out for yourself at [url]http://bellevue.com/includes/getByCategory.php[/url]

I was having a problem with my responseXML because of this so I narrowed it down to the actual php file. Here’s the php code:

[code=php]<?php
header(“Content-type: text/xml”);
echo ‘<?xml version=”1.0″ encoding=”UTF-8″?>’;
echo ‘<markers>’;
require(“prep.php”);
$category = “Asian”;

$query = “SELECT * FROM restaurants WHERE category = ‘$category'”;
$result = mysql_query($query) or die(“Query failed: “. mysql_error());
while($row = mysql_fetch_array($result)) {
echo ‘<marker lat=”‘, $row[‘lat’], ‘” lng=”‘, $row[‘lng’], ‘” html=”‘, $row[‘description’], ‘” label=”‘, $row[‘name’], ‘” />’;
}

echo ‘</markers>’;
?>
[/code]

Any ideas? Much thanks!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@scragarSep 12.2008 — I belive this comes from the fact that your placing HTML inside a tag, which appears to be causing an error, could you not repesent that as a child node?

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;markers&gt;
&lt;marker lat="43.65654" lng="-79.90138" label="Test" &gt;
&lt;html&gt;&lt;![CDATA[
Some stuff to display in the&lt;br&gt;First Info Window
]]&gt;&lt;/html&gt;
&lt;/marker&gt;
&lt;/markers&gt;

I'd have to know how you are inspecting the code and such to recommend anything better than this...
Copy linkTweet thisAlerts:
@tfk11Sep 12.2008 — If your data contains certain characters then they must be converted before being used as an attribute value.

[code=php]
htmlspecialchars($row['description'])
[/code]
Copy linkTweet thisAlerts:
@ratcatemeSep 12.2008 — try fixing the <'s and >'s using htmlspecialchars() like this

[code=php]echo '<marker lat="', $row['lat'], '" lng="', $row['lng'], '" html="', htmlspecialchars($row['description']), '" label="', $row['name'], '" />';[/code]

Scott.

oops got beaten to it.
Copy linkTweet thisAlerts:
@bejitto101authorSep 16.2008 — Much thanks for the help. But I'm still having that issue. I added the code and it worked when I just had one marker. More than one it freaks out.

Same page at http://bellevue.com/includes/getByCategory.php.
×

Success!

Help @bejitto101 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...