xml自定义标题? [英] xml custom header?

查看:129
本文介绍了xml自定义标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



是否可以将自定义标头添加到XML文件中?


因为可能会针对不同的版本更改数据结构。


希望读取自定义标头以区分哪个版本,然后解析数据结构。



谢谢和问候,


E-John



//版本1


类节点{


int Id;


}



//版本2


类节点{


int Id;


int ParentId;


}

解决方案

处理指令可用于类似于自定义标题的内容。但是,我不认为它们通常用于指示数据格式的版本。相反,某些XML文件格式(至少XSLT和SVG)在
根元素中具有版本属性。使用XmlReader处理起来非常简单:跳转到根元素,检查版本,然后转移到反序列化正确类型的代码。


你用什么来翻译对象到XML和back:XmlSerializer,DataContractSerializer,System.Xml.Linq或plain XmlWriter&的XmlReader?


Dear All,

Is it possible add custom header to XML file?

Because data structure may be changed for different version.

Hope to read the custom header to distinguish which version, then parse the data structure.

Thanks and regards,

E-John

// version 1

class Node {

int Id;

}

// version 2

class Node {

int Id;

int ParentId;

}

解决方案

Processing instructions can be used for something similar to custom headers. However, I don't think they are normally used for indicating the version of a data format. Instead, some XML file formats (at least XSLT and SVG) have a version attribute in the root element. That would be pretty simple to handle with XmlReader: skip to the root element, check the version, and then branch to code that deserializes the correct type.

What do you use for translating the objects to XML and back: XmlSerializer, DataContractSerializer, System.Xml.Linq, or plain XmlWriter & XmlReader?


这篇关于xml自定义标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆