xml序列化中的XML命名空间

编程入门 行业动态 更新时间:2024-10-24 10:23:49
本文介绍了xml序列化中的XML命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

SBML是系统生物学中的一种文件格式标准,它基于xml文件格式。当我在vb中使用xml序列化来读取sbml文件时,我遇到了问题,xml命名空间不正确,所以程序给我一个例外: System.Xml.dll中发生了'System.InvalidOperationException'类型的未处理异常 附加信息:XML文档中有错误(2,2)。 i认为这个错误发生在xml文件中xml根节点的位置:

< sbml xmlns = www.sbml/sbml/level2 version = 1 利el = 2 >

第2行,以及xmlns属性的位置。 i将sbml文件与普通xml文件进行比较,很容易发现xml根节点中的命名空间不同:

< MetaCyc xmlns:xsi = www.w3/2001/ XMLSchema-instance xmlns:xsd = www.w3/2001/XMLSchema >

所以我在vb中使用xml序列化时如何处理这个问题d sbml文件。

解决方案

在反序列化数据之前,必须定义所需的类。您将需要xsd文件(即XML架构)和xsd.exe用于该prupose。有关详细信息,请参阅我的文章 Bernie的Trackviewer [ ^ ],我用GPX文件描述了这一点(用XML编码的gps数据)

SBML is a kind of file format standard in the systems biology, and it is base on the xml file format. when i using the xml Serialization in vb to read the sbml file, then i get a problem, the xml namespace is not correct, so the program throw a exception to me: An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll Additional information: There is an error in XML document (2, 2). i think this error occur in the position of xml root node in a xml file :

<sbml xmlns="www.sbml/sbml/level2" version="1" level="2">

line 2 , and the position at xmlns attribute. i compare the sbml file with the normal xml file, easily found out that the namespace in a xml root node is diferrent:

<MetaCyc xmlns:xsi="www.w3/2001/XMLSchema-instance" xmlns:xsd="www.w3/2001/XMLSchema">

so how to deal with this problem when i using the xml Serialization in vb to read the sbml file.

解决方案

Before you can deserialize the data, you must define the required classes. You'll need the xsd file (i.e. XML schema) and xsd.exe for that prupose. For more details, see my article "Bernie’s Trackviewer[^]", where I described that with GPX files (gps data encoded in XML).

更多推荐

xml序列化中的XML命名空间

本文发布于:2023-11-09 06:03:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571581.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列化   空间   xml   XML

发布评论

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

>www.elefans.com

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