简体   繁体   English

如何反序列化没有命名空间等的xml ...?

[英]How to deserialize an xml that has no namespace, etc…?

I have a xml file that looks like this : 我有一个xml文件,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<config>
 <node id="1" />
</config>

Now I try to deserialize it, but always get the error : 现在我尝试反序列化它,但总是得到错误:

<config xmlns=''> was not expected

Anyone how to fix this ? 有人如何解决这个问题? I dont have any control over the xml. 我对xml没有任何控制权。

Thanx 感谢名单

Why not just load it in as a DOM (eg using XmlDocument or XDocument ) and extract the data yourself? 为什么不直接将它作为DOM加载(例如使用XmlDocumentXDocument )并自己提取数据? Assuming it wasn't saved with XmlSerializer , there's no point in trying to deserialize it that way. 假设它没有与XmlSerializer保存,那么尝试以这种方式反序列化是没有意义的。

EDIT: It would help if you'd give us some background here. 编辑:如果你在这里给我们一些背景,这将有所帮助。 If this isn't a valid XmlSerializer output, what is it? 如果这不是有效的XmlSerializer输出,它是什么? Was it originally a valid file, but something has stripped out the namespaces? 它原来是一个有效的文件,但有些东西剥离了名称空间? If so, what else has it done? 如果是这样,它还做了什么?

You may well be able to get away with just reapplying the namespace everywhere yourself (to every element) although that may be annoying do. 您可能只需自己(在每个元素上)重新应用命名空间即可逃脱,尽管这可能很烦人。 Currently we can't really tell though. 目前我们无法真正说出来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM