亲爱的所有人,
是否可以将自定义标头添加到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自定义标题?
发布评论