Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XML反序列化:如何获取实体代码而不是元素?_Xml_Vb.net_Deserialization_Xml Deserialization - Fatal编程技术网

XML反序列化:如何获取实体代码而不是元素?

XML反序列化:如何获取实体代码而不是元素?,xml,vb.net,deserialization,xml-deserialization,Xml,Vb.net,Deserialization,Xml Deserialization,我正在尝试反序列化一个XML文件,这是一个日文到英文的字典,这样我就可以在Windows窗体中显示信息。我还不太清楚XML和反序列化通常是如何工作的,所以如果我误解了术语,请耐心等待 我的代码可以很好地反序列化XML字典,并且可以访问每个条目的所有信息。但是,有时我想访问存储在XML文件中的一些信息,作为实体代码(?),而不是底层元素(?),我不知道如何做到这一点 这里有一个例子来说明我的意思: 在XML文件中,标记用于存储关于词条(形容词、名词等)词性的信息。该信息存储在每个词条的列表(字符串

我正在尝试反序列化一个XML文件,这是一个日文到英文的字典,这样我就可以在Windows窗体中显示信息。我还不太清楚XML和反序列化通常是如何工作的,所以如果我误解了术语,请耐心等待

我的代码可以很好地反序列化XML字典,并且可以访问每个条目的所有信息。但是,有时我想访问存储在XML文件中的一些信息,作为实体代码(?),而不是底层元素(?),我不知道如何做到这一点

这里有一个例子来说明我的意思:

在XML文件中,
标记用于存储关于词条(形容词、名词等)词性的信息。该信息存储在每个词条的列表(字符串)中(因为一个词条可能记录多个词性)。如果要查看单个词条的词性数据,可能是这样的:

    (0) "noun (common) (futsuumeishi)"  
    (1) "noun or participle which takes the aux. verb suru" 
    (2) "nouns which may take the genitive case particle `no'"  
<entry>
<ent_seq>1371320</ent_seq>
<k_ele>
<keb>水泳</keb>
<ke_pri>ichi1</ke_pri>
<ke_pri>news1</ke_pri>
<ke_pri>nf07</ke_pri>
</k_ele>
<r_ele>
<reb>すいえい</reb>
<re_pri>ichi1</re_pri>
<re_pri>news1</re_pri>
<re_pri>nf07</re_pri>
</r_ele>
<sense>
<!-- These are the tags I'm interested in -->
<pos>&n;</pos>
<pos>&vs;</pos>
<pos>&adj-no;</pos>
<gloss>swimming</gloss>
</sense>
...
...
</entry>
这是冗长的,当我在屏幕上显示一个条目时,我不想要所有这些信息。我对XML文件本身中使用的速记代码很满意,它将上述三项表示为
&n
&vs
&adj编号分别为。当反序列化程序遇到这些元素时,它会将它们转换为文件顶部属性列表中描述的详细形式,而不是我想要的简短形式

包含这些
pos
标记的特定条目的XML如下所示:

    (0) "noun (common) (futsuumeishi)"  
    (1) "noun or participle which takes the aux. verb suru" 
    (2) "nouns which may take the genitive case particle `no'"  
<entry>
<ent_seq>1371320</ent_seq>
<k_ele>
<keb>水泳</keb>
<ke_pri>ichi1</ke_pri>
<ke_pri>news1</ke_pri>
<ke_pri>nf07</ke_pri>
</k_ele>
<r_ele>
<reb>すいえい</reb>
<re_pri>ichi1</re_pri>
<re_pri>news1</re_pri>
<re_pri>nf07</re_pri>
</r_ele>
<sense>
<!-- These are the tags I'm interested in -->
<pos>&n;</pos>
<pos>&vs;</pos>
<pos>&adj-no;</pos>
<gloss>swimming</gloss>
</sense>
...
...
</entry>
下面是我用来反序列化
sense
元素的class对象,它包含
pos
元素:

<Serializable()>
<XmlType("sense")>
Public Class SenseElement
    <XmlElement("pos")>
    Public Property PartOfSpeech As List(Of String)
    <XmlElement("gloss")>
    Public Property Gloss As List(Of GlossElement)

    <XmlElement("stagk")>
    Public Property SenseRestrictedToKeyword As List(Of String)
    <XmlElement("stagr")>
    Public Property SenseRestrictedToReading As List(Of String)

    <XmlElement("xref")>
    Public Property CrossReference As List(Of String)
    <XmlElement("ant")>
    Public Property Antonym As List(Of String)
    <XmlElement("field")>
    Public Property Field As List(Of String)
    <XmlElement("dial")>
    Public Property Dialect As List(Of String)
    <XmlElement("s_inf")>
    Public Property SenseInformation As List(Of String)
    <XmlElement("misc")>
    Public Property Misc As List(Of String)
    <XmlElement("lsource")>
    Public Property LanguageSource As List(Of LanguageSourceElement)
End Class
所以问题是,如何提取XML文件中包含的
pos
标记的短格式数据,而不是属性列表中包含的长格式数据?有没有简单的解决方法?我更喜欢VB.NET中的答案,但只要解决方案解释得足够好,就不太重要了


另外,如果我误用了术语或不清楚,请随时建议对这个问题进行编辑。

那么,当序列化XML时,您希望将任何与外部实体内容匹配的元素作为实体引用写入吗?当XML被封送时,实体引用已经被解析。因此,您可能需要添加某种后处理步骤来转换序列化的XML,并使用实体引用查找/替换任何文本(如果其值匹配)。@MadsHansen是的,我相信您已经总结了我要做的事情。如果这不是通过反序列化过程本身可以完成的事情,那么我可能不得不离开它,因为反序列化程序已经花了30秒来处理我正在处理的文件,我不想让它变慢。(该文件超过400万行)我对.NETAPI不太熟悉,不知道什么是可能的或有多困难。所以,现在不要放弃。让我们看看有没有.NET大师有什么想法