regex - 泛化正则表达式 XML 验证
问题描述
我希望通过让例如Dim IDNumbers() As String = 'SOMETHING'
而不是单独写出字符串列表来使我的代码更好{"0", "1", "2", "3", "4"}
。我希望能够从我的 XML 文件中读取所有 ID、学生姓名和生日节点,而不必亲自去列出它们。我不确定如何做到这一点如果有人可以帮助提供示例代码,那就太好了。这样做的原因是,如果我修改文件中的代码,我也必须在我的 vb 代码中更改它。
解决方案
Try following :
Imports System.Xml
Imports System.Xml.Linq
Imports System.Globalization
Module Module1
Const FILENAME As String = "c:\temp\test.xml"
Sub Main()
Dim doc As XDocument = XDocument.Load(FILENAME)
Dim results = doc.Descendants("student").Select(Function(x) New With { _
.id = CType(x.Element("ID"), string), _
.name = CType(x.Element("student_name"), string), _
.birthday = CType(x.Element("birthday"), string) _
}).ToList()
End Sub
End Module
推荐阅读
- salesforce - 如何为 Salesforce 中的触发器编写单元测试?
- express - 使用带护照和快递的可选授权路线
- neo4j - Neo4J 中创建节点的吞吐量随着属性数量的增加而显着降低
- postgresql - 无法通过 pg_isready 或 pgAdmin 访问在 docker 中运行的 postgres
- python-3.x - 如何设置 tqdm 的 r_bar 部分
- android - Flutter Custompainter画布drawimage不起作用
- ios - iOS输入字段 - 输入文本时不可见
- rest - Sharepoint Rest API - 对扩展字段应用过滤器 - 状态 400
- c# - 无法将 MongoDB C# 驱动程序与 Hololens 一起使用
- javascript - Express-API POST 在 Postman 中有效,但不适用于 AJAX