XML文档中存在错误(159,8) [英] There is an error in XML document (159, 8)

查看:135
本文介绍了XML文档中存在错误(159,8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我目前正在处理如下结构的XML文件:



Hi everyone,

I'm currently dealing with an XML file structured like this:

<contatti>
    <sede>
        <name></name>					
    	<address></address>
	<tel></tel>
	<fax></fax>
	<email></email>
	<link></link>
	<iva></iva>
	<reg></reg>
	<timing></timing>
        <contacts>
                <contact>
		<surname></surname>
		<name></name>
		<area></area>
		<role></role>
		<tel></tel>
		<email></email>
        	</contact>
        </contacts>
    </sede>
</contatti>





为了序列化它的数据,我使用这个类:





To serialize its data I use this class:

{
    [XmlRoot("contatti")]
    public class Contatti
    {
        [XmlElement("sede")]
        public Sede[] ListaSedi { get; set; }

    }

    public class Sede
    {
        [XmlElement("name")]
        public string Name { get; set; }

        [XmlElement("address")]
        public string Address { get; set; }

        [XmlElement("tel")]
        public string Tel { get; set; }

        [XmlElement("fax")]
        public string Fax { get; set; }

        [XmlElement("email")]
        public string Email { get; set; }

        [XmlElement("link")]
        public string Link { get; set; }

        [XmlElement("iva")]
        public string Iva { get; set; }

        [XmlElement("reg")]
        public string Reg { get; set; }

        [XmlElement("timing")]
        public string Timing { get; set; }

        [XmlArray("contacts"), XmlArrayItem("contact")]
        public Contatto[] ListaContatti { get; set; }
    }

    [XmlRoot("contact")]
    public class Contatto
    {
        [XmlElement("surname")]
        public string Surname { get; set; }

        [XmlElement("name")]
        public string Name { get; set; }

        [XmlElement("area")]
        public string Area { get; set; }

        [XmlElement("role")]
        public string Role { get; set; }

        [XmlElement("tel")]
        public string Tel { get; set; }

        [XmlElement("email")]
        public string email { get; set; }
    }
}





问题是,当我启动应用程序时,它返回一个与序列化程序:

System.InvalidOperationException:XML文档中存在错误(159,8)。 - > System.Xml.XmlException:无法在具有的元素上调用ReadElementContentAs()方法儿童元素。第159行,第8位。



那么,我该怎么办?我检查了159行,但我没有注意到任何奇怪的事情。

这是一个截图 https://onedrive.live.com/redir?resid=69223EABCE34E2E5!17711&authkey=!AAK0_nwaieS7H-Y&v=3&ithint=photo %2cpng [ ^ ]



有人有线索吗?



谢谢大家!



The problem is, when I launch the app it returns an exception related to the serializer:
"System.InvalidOperationException: There is an error in XML document (159,8). --> System.Xml.XmlException: ReadElementContentAs() methods cannot be called on an element that has child elements. Line 159, position 8."

So, what do I do? I checked the 159 line but I've didn't noticed anything strange.
Here's a screenshot https://onedrive.live.com/redir?resid=69223EABCE34E2E5!17711&authkey=!AAK0_nwaieS7H-Y&v=3&ithint=photo%2cpng[^]

Someone has any clues?

Thank you to everyone!

推荐答案

我看不到屏幕截图,但这里有一些问题可以帮助你解决问题:



1.是否在您对数据进行反序列化时发生错误?

如果是这样,您是否尝试以XML格式打开文档?观众?如果发生错误,也许你会得到一些提示





2.你检查了158行吗? (有时这是失败之前的行)



3.这是第一次处理特定节点类型,例如<传真>或者< tel>?

如果没有,那个类型的节点有什么不同?



很难提供更多没有关于实际XML文件的更多信息的帮助。
I can't see the screen shot, but here are some questions for you that might help your trouble shooting:

1. Is it when you de-serialize the data that the error occurs?
If so, have you tried to open the document in an XML viewer? Maybe you will get some hints
if an error occur there too.

2. Have you checked line 158? (Sometimes it is the line before that fails)

3. Is it the first time a specific node type is processed, e.g. <fax> or <tel>?
If not, what is the difference from a node of that type that works?

Difficult to give more help without more info about the actual XML file.


这篇关于XML文档中存在错误(159,8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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