[UWP] [VB] IXmlSerializable示例:读取相同类型的ChildNodes [英] [UWP][VB]IXmlSerializable Examples: Reading ChildNodes of Same Type

查看:38
本文介绍了[UWP] [VB] IXmlSerializable示例:读取相同类型的ChildNodes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文件,其中包含自定义类的元素,定义为:

< XmlRoot()>公共类别组
< XmlAttribute()>私有财产MyAttribute()As String
< XmlArray()>私有财产子组()As Group()
Public Sub New()
End Sub
End Class




I希望涉及此内容的XML部分具有类似于以下内容的结构:

< Group MyAttribute =" myvalue1"> 
< Group MyAttribute =" myvalue2" />
< Group MyAttribute =" myvalue3" />
< Group MyAttribute ="">
< Group MyAttribute =" myvalue4" />
< Group MyAttribute =" myvalue5" />
< Group MyAttribute ="">
< Group MyAttribute =" myvalue6" />
< Group MyAttribute =" myvalue7" />
< / Group>
< / Group>
< / Group>




我是新手使用IXmlSerializable(虽然我多次使用XmlSerializer),所以我不太确定这该怎么做。我找到了XmlReader& XmlWriter有点令人困惑,确保Xml是我想要的方式我有时搞砸
的部分是确保SubGroups属性只是作为子节点呈现,而不是< SubGroups>< / SubGroups> ;。是否有任何好的网站或IXmlSerializable的例子?谢谢。



Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

< blockquote>

Hello Nathan Sokalski,


>>"IXmlSerializable有什么好的网站或示例吗?"


Youssef Moussaoui关于"使用XmlSerializer和DataContractSerializer自定义集合的XML "
应该对您有所帮助。


MSDN文档" 介绍XML序列化"对您来说也是一个良好的开端。


XML序列化示例


最好的问候,


Xavier Eoro


I have an XML file which contains elements of a custom class defined as:

<XmlRoot()> Public Class Group
	<XmlAttribute()> Private Property MyAttribute() As String
	<XmlArray()> Private Property SubGroups() As Group()
	Public Sub New()
	End Sub
End Class


I want the section of the XML involving this to have a structure similar to the following:

<Group MyAttribute="myvalue1">
  <Group MyAttribute="myvalue2"/>
  <Group MyAttribute="myvalue3"/>
  <Group MyAttribute="">
    <Group MyAttribute="myvalue4"/>
    <Group MyAttribute="myvalue5"/>
    <Group MyAttribute="">
      <Group MyAttribute="myvalue6"/>
      <Group MyAttribute="myvalue7"/>
    </Group>
  </Group>
</Group>


I am new to using IXmlSerializable (although I have used XmlSerializer many times), so I am not exactly sure how to do this. I found XmlReader & XmlWriter somewhat confusing, and the part of making sure the Xml is the way I want that I sometimes mess up is making sure that the SubGroups property is rendered as just child nodes, not as <SubGroups></SubGroups>. Are there any good sites or examples for IXmlSerializable? Thanks.


Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

Hello Nathan Sokalski,

>>" Are there any good sites or examples for IXmlSerializable?"

Youssef Moussaoui’s article about "Customizing the XML for collections with XmlSerializer and DataContractSerializer" should be helpful to you.

The MSDN document "Introducing XML Serialization" also is a good start for you.

Examples of XML Serialization

Best Regards,

Xavier Eoro


这篇关于[UWP] [VB] IXmlSerializable示例:读取相同类型的ChildNodes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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