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

Discussion in 'ASP .Net' started by pei_world, Jun 14, 2004.

  1. pei_world

    pei_world Guest

    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>
     
    pei_world, Jun 14, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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>
    >
    >
     
    S. Justin Gengo, Jun 14, 2004
    #2
    1. Advertising

  3. pei_world

    pei_world Guest

    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" <> wrote in message
    news:...
    > 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>
    >
    >
     
    pei_world, Jun 14, 2004
    #3
  4. 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" <> wrote in message
    news:...
    >
    > 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" <> wrote in message
    > news:...
    > > 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>
    > >
    > >

    >
    >
     
    S. Justin Gengo, Jun 14, 2004
    #4
  5. pei_world

    pei_world Guest

    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" <> wrote in message
    news:...
    > 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>
    >
    >
     
    pei_world, Jun 15, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,438
  2. Replies:
    9
    Views:
    63,698
    ChazZeromus
    Feb 25, 2012
  3. Lee
    Replies:
    3
    Views:
    2,891
  4. killy971
    Replies:
    2
    Views:
    687
    Johannes Koch
    Aug 15, 2008
  5. afshar
    Replies:
    3
    Views:
    24,962
    aljar
    May 19, 2010
Loading...

Share This Page