I have the following code in a default.aspx web form page_load event. There
seems to be a problem with line 5 (NewsArticle.Da te = line).
//create a news article
NewsArticle NewsArticle = new NewsArticle();
NewsArticle.Bod y = "This is a test news article...";
NewsArticle.Tit le = "Testing XML";
NewsArticle.Dat e = Convert.ToDateT ime("4/3/2008");
NewsArticle.ID = "1";
//serialize the NewsArticle into an xml document
XmlDocument NewsArticleXml = new XmlDocument();
XmlSerializer Serializer = new XmlSerializer(N ewsArticle.GetT ype());
StringBuilder SB = new StringBuilder() ;
StringWriter Writer = new StringWriter(SB );
Serializer.Seri alize(Writer, NewsArticle);
NewsArticleXml. LoadXml(SB.ToSt ring());
Response.Clear( );
Response.Conten tType = "text/xml";
NewsArticleXml. Save(Response.O utput);
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.Da te = line).
//create a news article
NewsArticle NewsArticle = new NewsArticle();
NewsArticle.Bod y = "This is a test news article...";
NewsArticle.Tit le = "Testing XML";
NewsArticle.Dat e = Convert.ToDateT ime("4/3/2008");
NewsArticle.ID = "1";
//serialize the NewsArticle into an xml document
XmlDocument NewsArticleXml = new XmlDocument();
XmlSerializer Serializer = new XmlSerializer(N ewsArticle.GetT ype());
StringBuilder SB = new StringBuilder() ;
StringWriter Writer = new StringWriter(SB );
Serializer.Seri alize(Writer, NewsArticle);
NewsArticleXml. LoadXml(SB.ToSt ring());
Response.Clear( );
Response.Conten tType = "text/xml";
NewsArticleXml. Save(Response.O utput);
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>
Comment