Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Parse error (help please)

Status
Not open for further replies.

tripwater

Programmer
Oct 13, 2004
12
US
I am new to XML. From my understanding the data between the tags is a string that can be in any format.

I am laying out a XSLT file when I find an error in the XML file.

Below is the code:

Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<inventory>
	<name>Inventory Account Totals</name>
	<dategen>3/10/2005 3:00pm</dategen>
	<enddate>3/10/2005</enddate>
	<parts>
		<item>
			<account>121.006</account>
			<desc>Inv - Parts - Briggs & Stratton</desc>
			<total>$1,096.92</total>
		</item>
		<item>
			<account>121.005</account>
			<desc>Inv - Parts - Cub Cadet</desc>
			<total>$2,432.05</total>
		</item>
		
		<parttotal>$3,500</parttotal>
	</parts>
	
	<units>
		<item>
			<account>121.006</account>
			<desc>Inv - Parts - Briggs & Stratton</desc>
			<total>$1,096.92</total>
		</item>
		<item>
			<account>121.005</account>
			<desc>Inv - Parts - Cub Cadet</desc>
			<total>$2,432.05</total>
		</item>
		
		<unittotal>$3,500</parttotal>
	</units>
</inventory>

Here is the error:

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Whitespace is not allowed at this location. Error processing resource 'file:///C:/Documents and Settings/US/Desktop/XML tes...

<desc>Inv - Parts - Briggs & Stratton</desc>
-------------------------------^




Why is this? Is it because of the "&"? I would like to think not. THis will majorly limit what I can do as all of this info is generated dynamically from a database. And I can not filter through everything checking for certain chars. I thought what ever is between an opening and closing tag is safe except of course < > = !=

Any thoughts?

Thank you for any help.
 
XML can only contain legal character as specified by the w3c spec for XML. Legal characters are tab, carriage return, line feed, and the legal characters of Unicode and ISO/IEC 10646. For more info, see:


So & must be replaced with its proper entity, which is &amp;

Also you doc is not well formed:
Code:
<unittotal>$3,500</parttotal>

This is a corrected version of your XML:
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<inventory>
  <name>Inventory Account Totals</name>
  <dategen>3/10/2005 3:00pm</dategen>
  <enddate>3/10/2005</enddate>
  <parts>
    <item>
      <account>121.006</account>
      <desc>Inv - Parts - Briggs &amp; Stratton</desc>
      <total>$1,096.92</total>
    </item>
    <item>
      <account>121.005</account>
      <desc>Inv - Parts - Cub Cadet</desc>
      <total>$2,432.05</total>
    </item>
    <parttotal>$3,500</parttotal>
  </parts>
  <units>
    <item>
      <account>121.006</account>
      <desc>Inv - Parts - Briggs &amp; Stratton</desc>
      <total>$1,096.92</total>
    </item>
    <item>
      <account>121.005</account>
      <desc>Inv - Parts - Cub Cadet</desc>
      <total>$2,432.05</total>
    </item>
    <parttotal>$3,500</parttotal>
  </units>
</inventory>
 
Hi tripwater,
Not sure if you've solved your problem. Anyway, just thought to offer a tip (in case you're not aware).

You can very quickly convert all the characters in a string to be 'legal' using the server.htmlEncode() method. So, it is actually quite easy...

regards,
- Joseph
============

~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 
THanks Joseph but the errors I am getting are within the XML file itself. Can you call

<descr>server.htmlEncode(Inv - Parts - Briggs & Stratton)</descr>

in an XML file? I tried it as I am new to all of this and it did not work. I am thinking your solution is for the XSLT not for the XML file. Am I wrong?

Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top