PC Review


Reply
Thread Tools Rate Thread

ASP.NET xmlns=''> was not expected problem

 
 
pei_world
Guest
Posts: n/a
 
      14th Jun 2004
I have followed a example from a book exactly, but it seems not working at
all.
can anyone tell me what is going on?


========= Global.asax.cs ============

public static Entry LoadEntry(String filename)
{
//construct the path
String filepath = XMLFilePath + "\\" + filename;
FileStream f = null;
Entry newEntry;

try
{
//open the file
f = new FileStream(filepath,FileMode.Open);

//create a serializer...
XmlSerializer serializer = new XmlSerializer(typeof(Entry));
newEntry = (Entry)serializer.Deserialize(f);
}
finally
{
//close the file
f.Close();
}
//retrun the entry..
return newEntry;
}


====== default.aspx.cs =======

//loading entry from xml file
Entry entry = Global.LoadEntry("address.xml");
this.lblCatalog.Text = entry.Catalog;
this.lblName.Text = entry.Name;
this.lblAddress.Text = entry.Address;

===== address.xml ========

<?xml version="1.0" encoding="utf-8" ?>
<Addr xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Catalog>novel</Catalog>
<Name>Sina</Name>
<Web>http://www.sina.com.cn</Web>
</Addr>


 
Reply With Quote
 
 
 
 
S. Justin Gengo
Guest
Posts: n/a
 
      14th Jun 2004
Pei_World,

What is the error you are receiving?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"pei_world" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have followed a example from a book exactly, but it seems not working at
> all.
> can anyone tell me what is going on?
>
>
> ========= Global.asax.cs ============
>
> public static Entry LoadEntry(String filename)
> {
> //construct the path
> String filepath = XMLFilePath + "\\" + filename;
> FileStream f = null;
> Entry newEntry;
>
> try
> {
> //open the file
> f = new FileStream(filepath,FileMode.Open);
>
> //create a serializer...
> XmlSerializer serializer = new XmlSerializer(typeof(Entry));
> newEntry = (Entry)serializer.Deserialize(f);
> }
> finally
> {
> //close the file
> f.Close();
> }
> //retrun the entry..
> return newEntry;
> }
>
>
> ====== default.aspx.cs =======
>
> //loading entry from xml file
> Entry entry = Global.LoadEntry("address.xml");
> this.lblCatalog.Text = entry.Catalog;
> this.lblName.Text = entry.Name;
> this.lblAddress.Text = entry.Address;
>
> ===== address.xml ========
>
> <?xml version="1.0" encoding="utf-8" ?>
> <Addr xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <Catalog>novel</Catalog>
> <Name>Sina</Name>
> <Web>http://www.sina.com.cn</Web>
> </Addr>
>
>



 
Reply With Quote
 
pei_world
Guest
Posts: n/a
 
      14th Jun 2004

Server Error in '/WebAddress' Application.
----------------------------------------------------------------------------
----

<Addr xmlns=''> was not expected.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: <Addr xmlns=''> was not
expected.

Source Error:

Line 93: //create a serializer...
Line 94: XmlSerializer serializer = new
XmlSerializer(typeof(Entry));
Line 95: newEntry = (Entry)serializer.Deserialize(f);
Line 96: }
Line 97: finally

Source File: .......global.asax.cs Line: 95

Stack Trace:

[InvalidOperationException: <Addr xmlns=''> was not expected.]

Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read4_
Entry()

[InvalidOperationException: There is an error in XML document (2, 2).]
System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,
String encodingStyle)
System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)
WebAddress.Global.LoadEntry(String filename) in
c:\inetpub\wwwroot\webaddress\global.asax.cs:95
WebAddress.Default.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\webaddress\default.aspx.cs:44
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()





"pei_world" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have followed a example from a book exactly, but it seems not working at
> all.
> can anyone tell me what is going on?
>
>
> ========= Global.asax.cs ============
>
> public static Entry LoadEntry(String filename)
> {
> //construct the path
> String filepath = XMLFilePath + "\\" + filename;
> FileStream f = null;
> Entry newEntry;
>
> try
> {
> //open the file
> f = new FileStream(filepath,FileMode.Open);
>
> //create a serializer...
> XmlSerializer serializer = new XmlSerializer(typeof(Entry));
> newEntry = (Entry)serializer.Deserialize(f);
> }
> finally
> {
> //close the file
> f.Close();
> }
> //retrun the entry..
> return newEntry;
> }
>
>
> ====== default.aspx.cs =======
>
> //loading entry from xml file
> Entry entry = Global.LoadEntry("address.xml");
> this.lblCatalog.Text = entry.Catalog;
> this.lblName.Text = entry.Name;
> this.lblAddress.Text = entry.Address;
>
> ===== address.xml ========
>
> <?xml version="1.0" encoding="utf-8" ?>
> <Addr xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <Catalog>novel</Catalog>
> <Name>Sina</Name>
> <Web>http://www.sina.com.cn</Web>
> </Addr>
>
>



 
Reply With Quote
 
S. Justin Gengo
Guest
Posts: n/a
 
      14th Jun 2004
Pei,

It looks like the error is actually in your xml document itself.


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"pei_world" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Server Error in '/WebAddress' Application.
> --------------------------------------------------------------------------

--
> ----
>
> <Addr xmlns=''> was not expected.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
>
> Exception Details: System.InvalidOperationException: <Addr xmlns=''> was

not
> expected.
>
> Source Error:
>
> Line 93: //create a serializer...
> Line 94: XmlSerializer serializer = new
> XmlSerializer(typeof(Entry));
> Line 95: newEntry = (Entry)serializer.Deserialize(f);
> Line 96: }
> Line 97: finally
>
> Source File: .......global.asax.cs Line: 95
>
> Stack Trace:
>
> [InvalidOperationException: <Addr xmlns=''> was not expected.]
>
>

Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read4_
> Entry()
>
> [InvalidOperationException: There is an error in XML document (2, 2).]
> System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,
> String encodingStyle)
> System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)
> WebAddress.Global.LoadEntry(String filename) in
> c:\inetpub\wwwroot\webaddress\global.asax.cs:95
> WebAddress.Default.Page_Load(Object sender, EventArgs e) in
> c:\inetpub\wwwroot\webaddress\default.aspx.cs:44
> System.Web.UI.Control.OnLoad(EventArgs e)
> System.Web.UI.Control.LoadRecursive()
> System.Web.UI.Page.ProcessRequestMain()
>
>
>
>
>
> "pei_world" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I have followed a example from a book exactly, but it seems not working

at
> > all.
> > can anyone tell me what is going on?
> >
> >
> > ========= Global.asax.cs ============
> >
> > public static Entry LoadEntry(String filename)
> > {
> > //construct the path
> > String filepath = XMLFilePath + "\\" + filename;
> > FileStream f = null;
> > Entry newEntry;
> >
> > try
> > {
> > //open the file
> > f = new FileStream(filepath,FileMode.Open);
> >
> > //create a serializer...
> > XmlSerializer serializer = new XmlSerializer(typeof(Entry));
> > newEntry = (Entry)serializer.Deserialize(f);
> > }
> > finally
> > {
> > //close the file
> > f.Close();
> > }
> > //retrun the entry..
> > return newEntry;
> > }
> >
> >
> > ====== default.aspx.cs =======
> >
> > //loading entry from xml file
> > Entry entry = Global.LoadEntry("address.xml");
> > this.lblCatalog.Text = entry.Catalog;
> > this.lblName.Text = entry.Name;
> > this.lblAddress.Text = entry.Address;
> >
> > ===== address.xml ========
> >
> > <?xml version="1.0" encoding="utf-8" ?>
> > <Addr xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> > <Catalog>novel</Catalog>
> > <Name>Sina</Name>
> > <Web>http://www.sina.com.cn</Web>
> > </Addr>
> >
> >

>
>



 
Reply With Quote
 
pei_world
Guest
Posts: n/a
 
      15th Jun 2004
I try to retrieve data in my adapter, no problem at all.
can you check it for me? Xml file is also included.


"pei_world" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have followed a example from a book exactly, but it seems not working at
> all.
> can anyone tell me what is going on?
>
>
> ========= Global.asax.cs ============
>
> public static Entry LoadEntry(String filename)
> {
> //construct the path
> String filepath = XMLFilePath + "\\" + filename;
> FileStream f = null;
> Entry newEntry;
>
> try
> {
> //open the file
> f = new FileStream(filepath,FileMode.Open);
>
> //create a serializer...
> XmlSerializer serializer = new XmlSerializer(typeof(Entry));
> newEntry = (Entry)serializer.Deserialize(f);
> }
> finally
> {
> //close the file
> f.Close();
> }
> //retrun the entry..
> return newEntry;
> }
>
>
> ====== default.aspx.cs =======
>
> //loading entry from xml file
> Entry entry = Global.LoadEntry("address.xml");
> this.lblCatalog.Text = entry.Catalog;
> this.lblName.Text = entry.Name;
> this.lblAddress.Text = entry.Address;
>
> ===== address.xml ========
>
> <?xml version="1.0" encoding="utf-8" ?>
> <Addr xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <Catalog>novel</Catalog>
> <Name>Sina</Name>
> <Web>http://www.sina.com.cn</Web>
> </Addr>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
deserialization problem (xmlns=''> was not expected) John Microsoft Dot NET Framework 0 6th Sep 2005 02:00 PM
xmlns=''> was not expected. Shailendra Batham Microsoft C# .NET 1 31st Aug 2004 01:42 AM
"<root xmlns=''> was not expected." when DeSerialize from xml string Julia Microsoft Dot NET Framework Forms 1 21st Jul 2004 12:37 PM
"<root xmlns=''> was not expected." when DeSerialize from xml string Julia Microsoft Dot NET 0 21st Jul 2004 11:30 AM
XPath problem with two xmlns Gismo Microsoft C# .NET 0 1st Apr 2004 12:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:38 PM.