xml自定义标题?

编程入门 行业动态 更新时间:2024-10-11 23:18:44
本文介绍了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自定义标题?

本文发布于:2023-10-30 07:23:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542168.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   标题   xml

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!