gpt4 book ai didi

xml - 如何在 VB.NET 中读取 XML 元素

转载 作者:行者123 更新时间:2023-12-04 05:38:38 34 4
gpt4 key购买 nike

我有一个非常简单的问题,但由于我是 XML 的新手,所以我遇到了一些问题。我有这个 XML 文档:

<?xml version="1.0" encoding="utf-8"?>  
<Form_Layout>
<Location>
<LocX>100</LocX>
<LocY>100</LocY>
</Location>
<Size>
<Width>300</Width>
<Height>300</Height>
</Size>
</Form_Layout>

我想做的是将 LocX、LoxY、Width 和 Height 元素的值读入相应的变量。

这是我尝试过的:

Dim XmlReader = New XmlNodeReader(xmlDoc)  
While XmlReader.Read
Select Case XmlReader.Name.ToString()
Case "Location"
If XmlReader.??
Case "Size"
If XmlReader.??
End Select
End While

但是,我不知道如何访问每个子节点。

最佳答案

如果您能够使用 Linq to XML,则可以使用 VB 的 XML Axis Properties :

Dim root As XElement = XDocument.Load(fileName).Root

Dim LocX = Integer.Parse(root.<Location>.<LocX>.Value)
Dim LocY = Integer.Parse(root.<Location>.<LocY>.Value)

root.<Location>.<LocY>.Value = CStr(120)也有效。

关于xml - 如何在 VB.NET 中读取 XML 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11581692/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com