We are building a website price comparison. For integrate stores with our website we using the .xml file (feed).
The feed file has a specific structure that is required to import products to our site correctly.
What we need:
How we can write a script that will verify the correctness of the provide .xml file.
example:
our file feed have required structure like:
<offers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1">
<o id="2576" url="https://urlshop.com/catalog/product/view/id/2576/s/jazz-2044-410-charcoal-pink/" price="390" avail="1" set="0" weight="2.0000" basket="1" stock="2">
<cat>
<![CDATA[ SHOES MEN > Sneakers ]]>
</cat>
<name>
<![CDATA[ Saucony JAZZ_2044 ]]>
</name>
<imgs>
<main url="https://urlshop.pl/pub/media/catalog/product/2/9/292864.jpg"/>
<i url="https://urlshop.pl/pub/media/catalog/product/2/9/292864_1.jpg"/>
<i url="https://urlshop.pl/pub/media/catalog/product/2/9/292865_1.jpg"/>
<i url="https://urlshop.pl/pub/media/catalog/product/2/9/292866_1.jpg"/>
<i url="https://urlshop.pl/pub/media/catalog/product/2/9/292867_1.jpg"/>
<i url=""/>
</imgs>
<desc>
<![CDATA[
New product with tags.
]]>
</desc>
<attrs>
<a name="Brand">
<![CDATA[ Saucony ]]>
</a>
<a name="product_code">
<![CDATA[ JAZZ_2044_410_CHARCOAL-PINK ]]>
</a>
<a name="Size">
<![CDATA[ 41, 42, 42.5, 43, 44, 44.5, 45, 46 ]]>
</a>
</attrs>
</o>
</offers>
We need build checker, when customer place in checker url link to feed and if feed have the same structure like above then return: The .xml file is correct!
If the file has a different structure, return the error.
@update
Ok,but now how to integrate this code with simple form like:
<form action="/action_page.php">
<fieldset>
<legend>Validation XML Feed:</legend>
Url to .xml file: <input type="url" name="firstname" value="">
<input type="submit" value="Submit">
</fieldset>
</form>
The usual approach is to write a schema (XSD) that describes the structure, and then to validate the instance against the schema. There are a number of XML development tools that will generate a first-cut schema from the instance (though it will never capture all the rules precisely). This is what oXygen generates for your instance document:
Of course, there's guesswork involved here. Just because none of your
a/@name
attributes contain spaces doesn't mean spaces aren't allowed.