xml序列化中的XML命名空间 [英] XML namespace in xml Serialization

查看:62
本文介绍了xml序列化中的XML命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SBML是系统生物学中的一种文件格式标准,它基于xml文件格式。当我在vb.net中使用xml序列化来读取sbml文件时,我遇到了问题,xml命名空间不正确,所以程序给我一个例外:



System.Xml.dll中发生了'System.InvalidOperationException'类型的未处理异常



附加信息:XML文档中有错误(2,2)。




i认为这个错误发生在xml文件中xml根节点的位置:



 <   sbml     xmlns   =  http://www.sbml.org/sbml/level2    version  < span class =code-keyword> =  1   利el   =  2 >  





第2行,以及xmlns属性的位置。



i将sbml文件与普通xml文件进行比较,很容易发现xml根节点中的命名空间不同:



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





所以我在vb.net中使用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.net 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="http://www.sbml.org/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="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">



so how to deal with this problem when i using the xml Serialization in vb.net 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命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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