473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

XmlDocument LoadXml

Hi
I want load whole xml file, I try do it in the same way as I did it in
windows application.

try

{

XmlDocument myDoc = new XmlDocument();

myDoc.LoadXml(Server.MapPath("cars.xml"));

}

catch ( Exception err )

{

message.Text = err.Message + err.StackTrace;

}

but I get error :

The data at the root level is invalid. Line 1, position 1

at System.Xml.XmlTextReader.ParseRoot() at System.Xml.XmlTextReader.Read()
at System.Xml.XmlValidatingReader.ReadWithCollectText Token() at
System.Xml.XmlValidatingReader.Read() at
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean
preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at
System.Xml.XmlDocument.LoadXml(String xml) at
myHoQ.WebForm1.ButtonCreate_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\myhoq\index.aspx.cs:line 66

line 66 :

myDoc.LoadXml(Server.MapPath("cars.xml"));

I'm new in asp.net. I don't konw why it works in C#(application) and
doesn't i asp.net. (Can we use DOM?)

Thanks


Nov 18 '05 #1
2 2733


Lupina wrote:

I want load whole xml file, I try do it in the same way as I did it in
windows application.

try

{

XmlDocument myDoc = new XmlDocument();

myDoc.LoadXml(Server.MapPath("cars.xml"));


You need to use the method Load which loads from a file or URL and not
the method LoadXml which is supposed to load the XML from a string so try
myDoc.Load(Server.MapPath("cars.xml"));
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 18 '05 #2
It works
Great Thanks
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Yechezkal Gutfreund | last post by:
I have been using the following code (successfully) to read Xml formated text packets from a TCP stream. The output from the server stream consists of a sequence of well formed Xml documents...
1
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid...
4
by: Robert Rossney | last post by:
I'm trying to send and receive XmlDocument objects using the System.Messaging.dll functions. The code I've written follows, as best I can tell, the methodology used in the sample code for the...
2
by: Eric Zechman via .NET 247 | last post by:
I have a project in which I get xml posted via a hidden form field (data=<xml></xml>). People are entering names like Bill & Sandy Smith. this is coming over as:...
1
by: AJ Brown | last post by:
I'm loading an XmlDocument object from a string using LoadXml. The string is a well-formed XML fragment (see example) and loads fine, however there are entities (&amp;) within attribute values. The...
2
by: Dave | last post by:
Hi, Is there an easier way to pull a subset of nodes from one XmlDocument to another? I have the code below but would like to know if there is a more streamlined method. Thanks, Dave ...
5
by: Bob P | last post by:
I have an example below that is not working correctly. I have a web application that passes a System.Xml.XmlDocument object "oInputDoc" around to functions byval. I do not want the "oInputDoc"...
4
by: saish | last post by:
Hello Need your help, I have a C++ win32 dll which takes xml document type by reference. I need to call this dll from c# .net. I tried using DllImport, but dll funtion when call does not...
4
by: Carlos Albert | last post by:
Hello, Would you tell me if there is a way to extract a single node as a new xmldocument? Thanks.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.