返回   cpper编程论坛 > 技术杂烩
注册账号 论坛帮助 会员列表 日历事件 搜索 今日新帖 标记版面已读

技术杂烩 找不到地方的技术问题?这里!

回复
 
LinkBack 主题工具 显示模式
  #1 (permalink)  
旧 2004-08-26
高级会员
 
注册日期: 2002-11-22
帖子: 249
clip 正向着好的方向发展
默认 [普通]a question about XmlTextReader.ReadBase64()

Hi, I am new to xml, so if I ask something stupid or funny, pls don't laugh.
my problem is like this:
I have a data structure like this
代码:
class mydata { byte[] data; }; // I wrote it to xml like this XmlTextureWriter writer; writer.WriteStartElement("MyData"); writer.WriteAttributeString("Length",md.data.Length.ToString()); writer.WriteBase64(md.data,0,md.data.Length); writer.WriteEndElement(); // I want to read it out XmlTextReader reader; while(reader.Read()) { switch(reader.NodeType) { case XmlNodeType.Element: MyData md = new MyData(); while(reader.MoveToNextAttribute()) { if(reader.Value == "Length") md.data = new byte[Int32.Parse(reader.Value)]; } reader.MoveToContent(); reader.ReaderBase64(md.data,0,md.data.Length); break; case XmlNodeType.EndElement: break; } }
Anyone has any suggestion?
Thanks a lot!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #2 (permalink)  
旧 2004-08-26
PingDong 的头像
高级会员
 
注册日期: 2004-06-25
帖子: 132
PingDong 正向着好的方向发展
默认

Sorry, I don't know what you want.Save some data in XML file, then read it?

You need a schema or DTD to define data structure first. It will like attachment. Sometime, data and schema save in same file, some time not.

XML data structure it isn't like the way you define class. It isn't define separately with the application.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #3 (permalink)  
旧 2004-08-27
高级会员
 
注册日期: 2002-11-22
帖子: 249
clip 正向着好的方向发展
默认

Sorry for the confusion.
What I wanted to do is save a data structure (i used to do that by save it as a binary file), this time I try to save it as xml. Since I am not familizr with xml at all, so possibly I have choose a stupid way doing this. I attach a simplified project to show how I do that. If there is more sophisticated or simpler way you can show me, it's very appreciated.

Please ignore my previous question, it's due to my understading of "EndElement".
上传的附件
文件类型: zip questionofxml.zip (6.4 KB, 3 次查看)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #4 (permalink)  
旧 2004-08-27
PingDong 的头像
高级会员
 
注册日期: 2004-06-25
帖子: 132
PingDong 正向着好的方向发展
默认

This sunday, I'm going to write a sample.

The easy way to handle XML is treat it as DataSet. You can simple import XML to DataSet. Then you use it like retrieve from Database.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #5 (permalink)  
旧 2004-08-28
高级会员
 
注册日期: 2002-11-22
帖子: 249
clip 正向着好的方向发展
默认

great! what I most care is write a data struture into xml and the read from it. if you can give an example of standard way doing it. that will be great. thx!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #6 (permalink)  
旧 2004-08-28
PingDong 的头像
高级会员
 
注册日期: 2004-06-25
帖子: 132
PingDong 正向着好的方向发展
默认

Here is a very simple demo source. When you click button - loadXML, it will load XML file's contents into a dataset. Then display it. After that you click button - SaveXML, it gonna save a new xml file named new_customer.xml. It very simple. But it show a quick way and mostly used way to handle XML contents.

After loaded Customers, it will append their name in TextBox, I use some XML concept to do that, XPath to get all names.

The XML source is also simple, I didn't write a schema for it. In real world, most XML come with a DTD or schema to tell you the XML content's structure.

The way you used, WriteStartElement.., it is like we create a HTTP stream from coding. But you know, we never create a website by that way. Mostly we create HTML sepearately and with some professional tools, and use some app to read it or save it. To XML, we do the same thing.
上传的附件
文件类型: zip xmlapp.zip (8.3 KB, 1 次查看)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #7 (permalink)  
旧 2004-08-28
PingDong 的头像
高级会员
 
注册日期: 2004-06-25
帖子: 132
PingDong 正向着好的方向发展
默认

MS hide tech behind that. Read XML as its structure(we common call it schema) it did by XML parser.

I think, for user, XPath is a great and interested thing. XPath is the way to find what you want in XML file.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #8 (permalink)  
旧 2004-08-29
高级会员
 
注册日期: 2002-11-22
帖子: 249
clip 正向着好的方向发展
默认

thx.
I can read and write xml from/to data structure now,see the attached code. The problem is anytime I change the data structure, I had to remember change both place. hope there is a better way.
上传的附件
文件类型: zip xml.zip (4.7 KB, 2 次查看)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #9 (permalink)  
旧 2004-08-29
PingDong 的头像
高级会员
 
注册日期: 2004-06-25
帖子: 132
PingDong 正向着好的方向发展
默认

I guess, you use C++ a long time and a smart guy. You are glad to do everything by your own code.

I just brief your code. I think you want to save instances of a Class in the XML file. Am I right? If yes, why don't you use XML serialize?

Check XmlSerializer Class in MSDN.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #10 (permalink)  
旧 2004-08-29
高级会员
 
注册日期: 2002-11-22
帖子: 249
clip 正向着好的方向发展
默认

thanks a lot.
this is exactly what I am looking for.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
回复

书签

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码
Trackbacks are 启用
Pingbacks are 启用
Refbacks are 启用


相似的主题
主题 主题作者 版面 回复 最后发表
question about reference parameter through bind2nd clip 技术杂烩 5 2004-04-26 03:49 AM
question about auto_ptr clip 技术杂烩 2 2004-03-24 12:30 PM
Question: C语言里,return能不能返回一个数组? xyz1848 技术杂烩 7 2003-12-13 05:22 PM
May I have a question? Lili yan Zion/测试 3 2003-05-29 02:03 PM
2 question geoffrey 技术杂烩 1 2003-03-17 11:50 AM


所有时间均为格林尼治时间 +9。现在的时间是 09:25 AM


Powered by vBulletin® 版本 3.7.0
版权所有 ©2000 - 2009,Jelsoft Enterprises Ltd.
(C) Copy Right All Right Reserved 2001 - 2007

Search Engine Friendly URLs by vBSEO 3.1.0