Jump to content

XML document must have a top level element


CMCollins

Recommended Posts

Seem you don't have schema ref element should start similar to <?xml version="1.0" encoding="utf-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xsd:element name="product">.... rest which binds this ref xmlns:xsdto these<xsd:element name="product">

Can't believe I missed that!!!You should IMO start over with one element and test against that... Edited by L8V2L
Link to comment
Share on other sites

I sort of have good news. After correcting the schema ref element, the test files I have been using now go through the validator without error.

 

At first I got this message: s4s-elt-must-match.1: The content of 'product' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: complextype.

 

I was able to find info that I needed to change complextype to complexType and that fixed that error.

 

Thanks to dsonesuk for sticking with me on this and getting me error free.

 

Now my problem is that if I use an xml with more than one product in it, I get the error message in Excel "Only one top level element is allowed in an XML document" which is what started my post thread in the first place. It's hanging up on the line that has the start tag of my second product. The multi-product xml works in the XML validator, but not in Excel. An xml with only one product also comes in properly in Excel now, which it didn't before.

Link to comment
Share on other sites

That is because your original is set up for one product only, the product element is root element where can only have one, you will have to set up a extra element to take each item of root product that can be displayed multiple times

 

example

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><product xsd:noNamespaceSchemaLocation="XSD file location" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"> <item>	<asin>B003Y3E55G</asin>	<brand>Hydrofarm</brand>	<title>Hydrofarm CK64081 7-Inch Vented Dome</title>	<category>Patio, Lawn &amp; Garden</category>	<description>Hydrofarm ck64081 7-inch vented humidity dome</description>	<wordcount>6</wordcount>	<rating>3.7</rating>	<review>87</review>	<listprice>0</listprice>	<price>12.88</price>	<discount>0%</discount>	<shipping>0</shipping>	<totalprice>0</totalprice>	<parentasin>B003Y3E55G</parentasin>	<available>True</available>	<fulfilled>False</fulfilled>	<thumbnail>http://ecx.images-am...VIL._AA160_.jpg</thumbnail>	<url>http://www.amazon.co...#38;amp;sr=1-24</url>	<imageurl>http://ecx.images-am...VIL._SS500_.jpg</imageurl>	<salesrank>2917</salesrank>	</item>	 <item>	<asin>B003Y3E55G</asin>	<brand>Hydrofarm</brand>	<title>Hydrofarm CK64081 7-Inch Vented Dome</title>	<category>Patio, Lawn &amp; Garden</category>	<description>Hydrofarm ck64081 7-inch vented humidity dome</description>	<wordcount>6</wordcount>	<rating>3.7</rating>	<review>87</review>	<listprice>0</listprice>	<price>12.88</price>	<discount>0%</discount>	<shipping>0</shipping>	<totalprice>0</totalprice>	<parentasin>B003Y3E55G</parentasin>	<available>True</available>	<fulfilled>False</fulfilled>	<thumbnail>http://ecx.images-am...VIL._AA160_.jpg</thumbnail>	<url>http://www.amazon.co...#38;amp;sr=1-24</url>	<imageurl>http://ecx.images-am...VIL._SS500_.jpg</imageurl>	<salesrank>2917</salesrank>	</item>	</product>

with xsd

<?xml version="1.0" encoding="utf-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> 	<xsd:element name="product">    <xsd:complexType>      <xsd:sequence>		<xsd:element name="item" maxOccurs="unbounded">	      <xsd:complexType>			<xsd:sequence>				<xsd:element name="asin" type="xsd:string" />				<xsd:element name="brand" type="xsd:string" />				<xsd:element name="title" type="xsd:string" />				<xsd:element name="category" type="xsd:string" />				<xsd:element name="description" type="xsd:string" />				<xsd:element name="wordcount" type="xsd:string" />				<xsd:element name="rating" type="xsd:string" />				<xsd:element name="review" type="xsd:string" />				<xsd:element name="listprice" type="xsd:string" />				<xsd:element name="price" type="xsd:string" />				<xsd:element name="discount" type="xsd:string" />				<xsd:element name="shipping" type="xsd:string" />				<xsd:element name="totalprice" type="xsd:string" />				<xsd:element name="parentasin" type="xsd:string" />				<xsd:element name="available" type="xsd:string" />				<xsd:element name="fulfilled" type="xsd:string" />				<xsd:element name="thumbnail" type="xsd:string" />				<xsd:element name="url" type="xsd:string" />				<xsd:element name="imageurl" type="xsd:string" />				<xsd:element name="salesrank" type="xsd:string" />			</xsd:sequence>		  </xsd:complexType>		</xsd:element>	  </xsd:sequence>    </xsd:complexType>  </xsd:element></xsd:schema>
  • Like 1
Link to comment
Share on other sites

It's working !!! (Jumping for Joy!!!) I now have a table with 1400+ records in it. I had to do a little cleanup. For example I had "item" in the xsd, but "Item" in the xml. I also had a couple of my fields in the xsd in a different order than they were in the xml. Once all that was fixed it worked.

 

The only thing I wish I could do now is get more than one review to automatically be imported in Excel. I've been reading about "repeating elements", but am not sure if that applies to what I'm doing.

 

For example the xml download I use has the following review data for one product.

 

<Author>J. Mitchell</Author> <RTitle>Excelent product</RTitle> <RRating>5</RRating> <Content>This dome is exactly what I needed .</Content> <Author>Gregory Blount</Author> <RTitle>Hydrofarm 7 inch vented dome</RTitle> <RRating>5</RRating> <Content>I found this dome to be superior quality compared to some of the specialty greenhouse offerings.</Content>

 

I was hoping they would load in as they do from my other scraper that would do:

 

Author1 RTitle1 RRating1 Content1 Author2 RTitle2 RRating2 Content2

 

Thanks again for all your help!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...