0

I am following this tutorial from google for google maps:

https://developers.google.com/maps/articles/phpsqlajax_v3?hl=es

I formatted my code as so:

echo '<markers>';

// Iterate through the rows, adding XML nodes for each
for($i = 0; $i< $breweryNum; $i++ ){

    echo '<marker ';
    echo 'name="' . parseToXML($row['beerBrewery']) . '" ';
    echo 'lat="' . $row['lat'] . '" ';
    echo 'lng="' . $row['longi'] . '" ';
    echo '/>';


}

// End XML file
echo '</markers>';

But when I run the php file to test my xml, I get this:

XML Parsing Error: not well-formed
Location: http://beerportfolio.com/getMapMarkers.php
Line Number 1, Column 18:<markers><marker <br />
-----------------^

2 Answers 2

2

Are you use nl2br or some to output resulting string?

It's clear error message, after "<markers><marker" outputs tag "<br />" but here should be your "name" attribute. Anyway, you can use following code to not output wrong things:

$out = '<markers>';
for($i = 0; $i< $breweryNum; $i++ ){

    $out .= '<marker ';
    $out .= 'name="' . parseToXML($row['beerBrewery']) . '" ';
    $out .= 'lat="' . $row['lat'] . '" ';
    $out .= 'lng="' . $row['longi'] . '" ';
    $out .= '/>';

}
$out .= '</markers>';
Sign up to request clarification or add additional context in comments.

6 Comments

Tried your code, and now I get this error: XML Parsing Error: no element found Location: beerportfolio.com/getMapMarkers.php Line Number 1, Column 1: ^ When I use this code: $out = '<?xml version="1.0" encoding="UTF-8" ?>'; // Iterate through the rows, adding XML nodes for each $out = '<markers>'; for($i = 0; $i< $breweryNum; $i++ ){ $out .= '<marker '; $out .= 'name="' . $row['beerBrewery'] . '" '; $out .= 'lat="' . $row['lat'] . '" '; $out .= 'lng="' . $row['longi'] . '" '; $out .= '/>'; } $out .= '</markers>';
You probably forget to echo $out;
Also, I think you need provide more code. You iterating by $breweryNum but outputting data from $row
SO I was an idiot and didt echo the $out but I am still getting more errors: Here is more code: $resultBrew = $db->query($query); $breweryNum = $resultBrew->num_rows; $out = '<?xml version="1.0" encoding="UTF-8" ?>'; // Iterate through the rows, adding XML nodes for each $out = '<markers>'; for($i = 0; $i< $breweryNum; $i++ ){ $row = $resultBrew->fetch_assoc(); $out .= '<marker '; $out .= 'name="' . parseToXML($row['beerBrewery']) . '" '; $out .= 'lat="' . $row['lat'] . '" '; $out .= 'lng="' . $row['longi'] . '" '; $out .= '/>'; } $out .= '</markers>'; echo $out;
Now I see in source of beerportfolio.com/getMapMarkers.php error message, what parsetoxml() is not defined. In example what you code is based on (developers.google.com/maps/articles/phpsqlajax_v3?hl=es), this function is presented. So, you need copy it into you code too
|
0

First up, XML files often begin with their type declaration. This isn't required but is helpful (i.e. <?xml version="1.0" encoding="UTF-8" ?> )

You seem to have <br /> being output within your xml. You may find it simpler to instead do something like

$strOutput = '<markers>';

And then

$strOutput .= '<marker name="' . parseToXML($row['beerBrewery']) . '" lat="' . $row['lat'] . '" lng="' . $row['longi'] . '" />';

And closing off with

$strOutput = '</markers>';
echo $strOutput;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.