0

Before I begin, I have read through the following discussions:

XML Parsing Error: not well-formed

XML not well formed error

error: Error parsing XML: not well-formed (invalid token) ...?

All of these questions didn't appear to be applicable to my issues.

I have built a php file, with a $xml=simplexml_load_file('somefile.xml'); function, for the purpose of building a product displaying, merchant affiliate site.

I then coded a(several) $feed(s), echo, the whole nine yards.

All the XML data is information about specific products (product name, description, price, size, image url's, other keyword relevant data, etc).

En example of one data entry is:

<?xml version="1.0" encoding="utf-8"?>
<root>
    <product>
        <productName>Name</productName>
        <productCode>someCode</productCode>
        <productDescription>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</productDescription>
        <productSort>someSort</productSort>
        <productCategory>someCategory</productCategory>
        <productUrl>http://www.someMerchantUrl.com/someFolderOrCategory/someProduct</productUrl>
        <productImageUrl01>http://www.someMerchantUrl.com/imageOne.jpg</productImageUrl01>
        <productImageUrl02>http://www.someMerchantUrl.com/imageTwo.jpg</productImageUrl02>
        <productImageUrl03>http://www.someMerchantUrl.com/imageThree.jpg</productImageUrl03>
        <productPrice>£26.50</productPrice>
        <productPriceSale></productPriceSale>
        <deliveryCost>$5.00</deliveryCost>
        <deliveryMethod>courier</deliveryMethod>
        <availability>In Stock</availability>
        <purchaseAgreement>http://www.someMerchantUrl.com/terms-and-conditions.html</purchaseAgreement>
        <mainColour>blue</mainColour>
        <secondaryColour>black</secondaryColour>
        <keyword01>keywordOne</keyword01>
        <keyword02>keywordTwo</keyword02>
        <keyword03>keywordthree</keyword03>
    </product>
</root>

Everything tested perfectly with sample URL's for the product links, and of their image locations.

The Parsing error popped up only after inserting the actual deep link URL ('click-redirect' coding).

So, the error I get is:

XML Parsing Error: not well-formed
Location: http://www.someAffiliateWebSite.com/productsXML/MainPageProducts.xml
Line Number 11, Column 68:
<productUrl>http://www.awin1.com/cread.php?awinmid=XXXX&awinaffid=XXXXXX&clickref=&p=http%3A%2F%2Fwww.someMerchantWebSite.com%2Fcatalog%2Fproduct.xml%3Fproduct_id%3D2577714%3Bcategory_id%3D2003473</productUrl>
---------------------------------------------------------------------------------^

((The affiliate network is Affiliate Window, the merchant and affiliate id's are obviously not X's, and the domains are obviously not what they are here.))

So, by deduction (I think it is deductive reasoning..... anyway) I presume that there is something funny within the Deep linking URL syntax, since it worked fine before I added the 'click-redirect' linking.

I see that it gives me specific information as to the location of the parsing error, but since I am measurably retarded in web development, that is of little use.

So can anyone find the fly in the soup here?

Thanks!

/Brian

Community
  • 1
  • 1
brian-welch
  • 441
  • 1
  • 7
  • 19

2 Answers2

3

Xml specification doesn't allow '&' in it's pure form. See http://www.w3.org/TR/xml/#syntax

Use CDATA for encapsulating the url, should work fine then

Edit: if you are sure that you don't get any other problematic characters, just doing a string replace for & to &amp; would also suffice.

Herbert
  • 5,698
  • 2
  • 26
  • 34
zelexir
  • 784
  • 5
  • 16
  • That was the ticket, thanks for the heads up. Once again, Stackoverflow gives me results beyond my competence... ain't the internet grand? :-D – brian-welch Sep 09 '12 at 11:34
0

You must properly escape the URLs in your XML.

See: What characters do I need to escape in XML documents?

Community
  • 1
  • 1
FilmJ
  • 2,011
  • 3
  • 19
  • 27