简体   繁体   中英

XML malformed but i don't know why

I have the following XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<results>
<ip>195.72.186.157</ip>
<country>UNITED KINGDOM (UK)</country>
<city>Oxford</city>
<latitude>51.75</latitude>
<longitude>-1.25</longitude>
<staticmap>http://maps.google.com/maps/api/staticmap?center=51.75,-1.25&sensor=false&zoom=13&size=500x300</staticmap>
<dynamicmap>http://maps.google.co.uk/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=51.75,-1.25&amp;sll=52.7115,-2.0006&amp;sspn=0.07831,0.264187&amp;ie=UTF8&amp;ll=51.75,-1.25&amp;spn=0.048204,0.132093&amp;z=14&amp;output=embed</dynamicmap>
</results>

The problem is it is coming up as malformed when I validate it. The character in question that it doesn't like is an equals sign. What is its problem with it? I validated it here:

http://www.w3schools.com/dom/dom_validate.asp

You're missing an amp; next to the sensor parameter in the staticmap element. In fact, you need to encode all ampersands in that element value.

Your need to encode your ampersands in the Google Maps URL, ie

<staticmap>http://maps.google.com/maps/api/staticmap?center=51.75,-1.25&amp;sensor=false&amp;zoom=13&amp;size=500x300</staticmap>

You did it for the <dynamicmap> , but not the <staticmap>

those charackters are reserved in xml. you can either replace them with their charcode equivalents (using &#NNN;) or wrap the urls in a CDATA section

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM