xml - 如何找到与变量值匹配的特定节点?
问题描述
有人可能会说这个问题与上一个问题相似,但它也不同。我有 ObjXmlSimpleTypeDoc 对象,它有两个 EnumerationValue 节点。每个 EnumerationValue 都有子节点。
我只想找到正确的 EnumerationValue 节点,它的 @code 与变量 strCourtNCIC 中的值匹配。在这个问题中 strCourtNCIC=MN010015J。对于这个问题,strCourtNCIC 保存一个值 MN010015J。
如何在 VB.NET 中执行此操作?我的 VB.NET 代码为 objXmlEnumerationValueNode 返回 Nothing,即使我希望看到带有 @code = MN010015J 的节点
如何更改我的 VB.NET 代码行以使用与 strCourtNCIC 值匹配的@code 查找 EnumerationValue 节点?
这是对象 ObjXmlSimpleTypeDoc
<SimpleTypeCompanion enumerates="CourtLocationTextType">
<EnumerationValue code="MN010015J">
<Text>Emily County</Text>
<AssociatedValue type="MNCISNodeID">
<Text>111</Text>
</AssociatedValue>
<AssociatedValue type="CountyName">
<Text>Emily</Text>
</AssociatedValue>
<AssociatedValue type="PhoneNumber">
<Text>724-820-7123</Text>
</AssociatedValue>
</EnumerationValue>
<EnumerationValue code="DC19DAKDC">
<Text>Pope County</Text>
<AssociatedValue type="MNCISNodeID">
<Text>112</Text>
</AssociatedValue>
<AssociatedValue type="CountyName">
<Text>Pope</Text>
</AssociatedValue>
</EnumerationValue>
</SimpleTypeCompanion>
这是我需要帮助才能获得与 strCourtNCIC (MN010015J) 匹配的正确 EnumerationValue 的 VB.NET 代码。
'CourtNCIC
strCourtNCIC = objXmlMNCISData.DocumentElement.SelectSingleNode("Case/Court/CourtNCIC").InnerText
'Access the CourtLocationTextType simple type.
objXmlSimpleTypeDoc = Msc.Integration.CourtXml.Library.v4.SimpleType.GetCompanionFile("CourtLocationTextType")
'Get the correct EnumerationValue node that has @code =MN010015J string value
objXmlEnumerationValueNode = objXmlSimpleTypeDoc.SelectSingleNode("/SimpleTypeCompanion/EnumerationValue[@code=" + strCourtNCIC + "]/@code")
解决方案
这是我的解决方案。这是值周围缺少单引号的情况!
objXmlEnumerationValueNode = objXmlSimpleTypeDoc.SelectSingleNode("/SimpleTypeCompanion/EnumerationValue[@code='" + strCourtORI + "']")
推荐阅读
- javascript - 如何使用 JavaScript 在 DateEdit 中添加天数
- javascript - jQuery函数在每次点击时运行多次
- json - 如何使用 PUT 和 JSON 更新 Podio 项目?
- .net - 无法从 App.Config 中的 AppSettings 获取键值对
- javascript - 如何根据表单的脏属性更改提交按钮的可用性?
- javascript - React 组件内的递归函数 TypeError: * is not a function
- arduino - Setup() 多次运行。在 VS Code 中使用 PlatformIO
- python - 执行运行异步函数
- reactjs - 滚动视图不适用于页面中的更多元素
- django - 使用 Django 子查询作为 FROM 表或 CTE 以便在聚合上有一个窗口?