Jump to content

Newbie - Try Again - XML Script Failure - HELP ME!


TrudyD1474
 Share

Recommended Posts

Ok, I'm NEW. I've read through the xml on w3Schools several times.I'm getting the following error:XML Parsing Error: not well-formedLocation: http://www.evergreen-implement.com/JD-xml3.xmlLine Number 20, Column 20:for (i=0;i<x.length;i++)-------------------^The coding is exactly the same as in the xml example and I also read the loop information and that confirms this looks good.OBJECTIVE: John Deere has an xml file of our available used equipment. I want to list this on our site. I have the URL, KEY, and PASSWORD and they say that is all I need to know. John Deere Tech's comment is "We design this XML-over_Http feed to be pulled by a server (up to 6x/day_. That server would then-update a local database, which powers the dealer's Web site, or-generate a set of static HTML pages for the dealer's Web site.-our best advice is to use available HTTP libraries in their desired language to access the information.The following is my code copied from "xml to HTML". I have changed the URL and hopefully added a password and key which I put into xmlhttp.send...I couldn't find a good example so I'm not sure if I did that correctly. Obviously in the passage below I have changed the key and password.Do I use a POST or a GET. I get the same message either way.The file format is:<machines> Whole file <machine> There are about 280 machines <elements> many elements per machine.....Do I use <machines> or <machine> In the folllowing statement; var x=xmlDoc.getElementsByTagName("machines");A copy of the xml file follows the xml. John Deere sent me this file.

<?xml version="1.0" encoding="UTF-8"?><html><body><script type="text/javascript">if (window.XMLHttpRequest)  {// code for IE7+, Firefox, Chrome, Opera, Safari  xmlhttp=new XMLHttpRequest();  }else  {// code for IE6, IE5   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }[color="#FF0000"]xmlhttp.open("POST","http://www.machinefinder.com/dealer_families/9398/machine_feed.xml",false);xmlhttp.send("key=448a6970-a02e","password=mypassword");[/color]xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>");var x=xmlDoc.getElementsByTagName("machines");for (i=0;i<x.length;i++)  {   document.write("<tr><td>");  document.write(x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue);  document.write("</td><td>");  document.write(x[i].getElementsByTagName("model")[0].childNodes[0].nodeValue);  document.write("</td></tr>");  }document.write("</table>");</script></body>

Example of xml From John deere:

<?xml version="1.0" encoding="UTF-8"?><machines>	<dealer_family_id>9398</dealer_family_id>	<timestamp>2011-Aug-04 17:03:31 CDT</timestamp>	<machine>		<id>938672</id>		<images>			<image primary="true">				<filePointer>http://www.machinefinder.com/images/machines/72/938672/1244855_large_22518.jpg</filePointer>			</image>			<image>				<filePointer>http://www.machinefinder.com/images/machines/72/938672/1244859_large_35747.jpg</filePointer>			</image>		</images>		<options>			<option>				<label>Configuration</label>				<value>Standard</value>			</option>			<option>				<label>Operator's Station</label>				<value>No Cab</value>			</option>			<option>				<label>Front Axle or Drive System</label>				<value>2WD</value>			</option>			<option>				<label>Transmission</label>				<value>Collarshift</value>			</option>			<option>				<label>Speeds Forward</label>				<value>9</value>			</option>			<option>				<label>Speeds Reverse</label>				<value>3</value>			</option>			<option>				<label>Loader</label>				<value>Yes</value>			</option>			<option>				<label>Describe</label>				<value>553 #13277</value>			</option>			<option>				<label>Rear Tire Size</label>				<value>13.6/-28</value>			</option>			<option>				<label>Radials</label>				<value>Bias</value>			</option>			<option>				<label>Front Tire Size</label>				<value>27/9.50-15</value>			</option>			<option>				<label>Rear</label>				<value>50</value>			</option>			<option>				<label>Front</label>				<value>50</value>			</option>			<option>				<label>3 Point Hitch</label>				<value>Standard</value>			</option>			<option>				<label>PTO</label>				<value>540</value>			</option>			<option>				<label>SCVs</label>				<value>2</value>			</option>			<option>				<label>Engine Hours</label>				<value>1750</value>			</option>		</options>		<description>Loader is new with full factory warranty</description>		<advertised_price>			<amount>19900</amount>			<currency>USD</currency>		</advertised_price>		<wholesale_price>			<amount>19900</amount>			<currency>USD</currency>		</wholesale_price>		<dealerId>070859</dealerId>		<category>Tractors - Utility (40-100hp)</category>		<manufacturer>John Deere</manufacturer>		<model>5210 & Loader</model>		<serialNumber>LV5210S320370</serialNumber>		<operationHours>1750</operationHours>		<modelYear>2000</modelYear>		<isNew>false</isNew>		<horsePower>45</horsePower>		<vatPct></vatPct>		<separatorHours></separatorHours>		<createdTimestamp>2009-05-13 16:29:55 -0400</createdTimestamp>		<modifiedTimestamp>2011-07-15 12:00:10 -0400</modifiedTimestamp>		<stockNumber>May 2009</stockNumber>		<locationNotes>Moses Lake</locationNotes>	</machine>

Link to comment
Share on other sites

Test to see if your XML is valid in the validator: http://validator.w3.org/#validate_by_input
I ran my code through a xml validator. Below is what they gave me:
 Line3 File name:	http://www.evergreen-implement.com/JD-xml3.xml  Column:	33  Error:	Can not find declaration of element 'script'.  But it's there!!!!!! :facepalm:     Error Position:	<script type="text/javascript">  Line18 File name:	http://www.evergreen-implement.com/JD-xml3.xml  Column:	21  Error:	Element type "x.length" must be followed by attribute specifications: ">" or "/>".   This is exactly what's in the example.    Error Position:	for (i=0;i<x.length;i++)

So the first error, it says the ">" is not there but it is.The second error doesn't like the ";" but I copied the code exactly from the W3c example.So there must be something else wrong that the validator isn't pointing out.HELP!

Link to comment
Share on other sites

I ran my code through a xml validator. Below is what they gave me:
 Line3 File name:	http://www.evergreen-implement.com/JD-xml3.xml  Column:	33  Error:	Can not find declaration of element 'script'.  But it's there!!!!!! :facepalm:     Error Position:	<script type="text/javascript">  Line18 File name:	http://www.evergreen-implement.com/JD-xml3.xml  Column:	21  Error:	Element type "x.length" must be followed by attribute specifications: ">" or "/>".   This is exactly what's in the example.    Error Position:	for (i=0;i<x.length;i++)

So the first error, it says the ">" is not there but it is.The second error doesn't like the ";" but I copied the code exactly from the W3c example.So there must be something else wrong that the validator isn't pointing out.HELP!

Line 20 shows:for (i=0;i<x.length;i++)Apparantly the validator, etc. doesn't like the "<", so it thinks the ";" is an error should probably be ">". So there must be someplace to let this know that this is the correct format but I don't know where to look. Here are the first lines of code, is it there that I need to make the changes? I have no idea how to fix this.
<?xml version="1.0" encoding="iso-8859-1"?><script type="text/javascript">

The validator also doesn't like line 18:document.write("</table>");It says "You may nave negelcted to close an element, or perhaps you meant to "self-close" an element, that, ending it with "/>" instead of ">".So could this be the same issue as above?Since I copied this from w3schools, I suspect that it is how I am wrapping the code I copied from the site.So can you take a look at that?

<?xml version="1.0" encoding="iso-8859-1"?><script type="text/javascript">if (window.XMLHttpRequest)  {// code for IE7+, Firefox, Chrome, Opera, Safari  xmlhttp=new XMLHttpRequest();  }else  {// code for IE6, IE5   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }xmlhttp.open("GET","http://www.machinefinder.com/dealer_families/9398/machine_feed.xml",false);xmlhttp.send("key=448a6970-a02e-012e-d5e6-005056be003c","password=Evergreen");xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>");var x=xmlDoc.getElementsByTagName("machine");for (i=0;i<x.length;i++)  {  document.write("<tr><td>");  document.write(x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue);  document.write("</td><td>");  document.write(x[i].getElementsByTagName("model")[0].childNodes[0].nodeValue);  document.write("</td></tr>");  }document.write("</table>");</script>

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
 Share

×
×
  • Create New...