I am trying to implement a solution to display XML data on a web page. I'm making use of an ASP.NET MVC Razor view. Testing the application out I used the following:
<script type="text/javascript">
LoadXMLString('XMLHolder', '<Rfq><IsAbove30k>true</IsAbove30k><ReferenceNumber>ReferenceNumber1</ReferenceNumber><ContactPersonName>ContactPersonName1</ContactPersonName><ContactPersonTelephoneNumber>ContactPersonTe1</ContactPersonTelephoneNumber><ContactPersonCellPhone>ContactPersonCe1</ContactPersonCellPhone><BuyerName>BuyerName1</BuyerName><BuyerTelephoneNumber>BuyerTelephoneN1</BuyerTelephoneNumber><BuyerEmailAddress>BuyerEmailAddress1</BuyerEmailAddress><ProcurementItem><Title>Title1</Title><ClosingDate>1900-01-01T01:01:01+02:00</ClosingDate><Description>Description1</Description><CaptureDate>1900-01-01T01:01:01+02:00</CaptureDate></ProcurementItem><RfqGood><DeliveryTo>DeliveryTo1</DeliveryTo><DeliveryAddress>DeliveryAddress1</DeliveryAddress><DeliverySuburb>DeliverySuburb1</DeliverySuburb><DeliveryPostalCode>1</DeliveryPostalCode><SubmissionFax>SubmissionFax1</SubmissionFax><Specification>Specification1</Specification><SubmissionFax2>SubmissionFax21</SubmissionFax2><DeliveryDate>1900-01-01T01:01:01+02:00</DeliveryDate><Good>Tools & Machinery</Good></RfqGood></Rfq>')
This worked fine. The XML data I'm trying to display is saved as XML in my application database. It is passed to the view in the model. Hence, I tried the following:
<script type="text/javascript">
LoadXMLString('RfqXmlData', @Html.Raw(Model.RfqXmlData))
At this stage I received the error:
Uncaught SyntaxError: Unexpected token <
I did notice when view the source of the web page that the XML data had linebreaks between the nodes:
So, naturally I tried removing the linebreaks:
<script type="text/javascript">
LoadXMLString('RfqXmlData', @Html.Raw(Model.RfqXmlData.Replace(System.Environment.NewLine, ""))
This succeeded in removing the linebreaks, but I still got the same error:
I have not idea why this is not working, as it did work when I loaded the xml string manually in the JavaScript.