A
Andy B
I have the following code in a default.aspx web form page_load event. There
seems to be a problem with line 5 (NewsArticle.Date = line).
//create a news article
NewsArticle NewsArticle = new NewsArticle();
NewsArticle.Body = "This is a test news article...";
NewsArticle.Title = "Testing XML";
NewsArticle.Date = Convert.ToDateTime("4/3/2008");
NewsArticle.ID = "1";
//serialize the NewsArticle into an xml document
XmlDocument NewsArticleXml = new XmlDocument();
XmlSerializer Serializer = new XmlSerializer(NewsArticle.GetType());
StringBuilder SB = new StringBuilder();
StringWriter Writer = new StringWriter(SB);
Serializer.Serialize(Writer, NewsArticle);
NewsArticleXml.LoadXml(SB.ToString());
Response.Clear();
Response.ContentType = "text/xml";
NewsArticleXml.Save(Response.Output);
The result of the last line above in a web browser is this: Any idea where
the date attribute went? The NewsArticle object above was converted with xsd
from a schema to a class.
<?xml version="1.0" encoding="utf-8" ?>
- <NewsArticle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" ID="1" Title="Testing XML">
<Body>This is a test news article...</Body>
</NewsArticle>
seems to be a problem with line 5 (NewsArticle.Date = line).
//create a news article
NewsArticle NewsArticle = new NewsArticle();
NewsArticle.Body = "This is a test news article...";
NewsArticle.Title = "Testing XML";
NewsArticle.Date = Convert.ToDateTime("4/3/2008");
NewsArticle.ID = "1";
//serialize the NewsArticle into an xml document
XmlDocument NewsArticleXml = new XmlDocument();
XmlSerializer Serializer = new XmlSerializer(NewsArticle.GetType());
StringBuilder SB = new StringBuilder();
StringWriter Writer = new StringWriter(SB);
Serializer.Serialize(Writer, NewsArticle);
NewsArticleXml.LoadXml(SB.ToString());
Response.Clear();
Response.ContentType = "text/xml";
NewsArticleXml.Save(Response.Output);
The result of the last line above in a web browser is this: Any idea where
the date attribute went? The NewsArticle object above was converted with xsd
from a schema to a class.
<?xml version="1.0" encoding="utf-8" ?>
- <NewsArticle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" ID="1" Title="Testing XML">
<Body>This is a test news article...</Body>
</NewsArticle>