1

我是新来的——我希望我把它贴在正确的地方。

作为我下面帖子的更新,我找到了一种获取地址城市部分的方法。我真的不需要原始帖子中建议的最大值;我只需要最后一个值,因为“xyz:sequenceNumber”值总是按顺序排列的。所以我尝试了这个:

tmpCity = xNode.selectSingleNode("//abc:Person//xyz:Region").previousSibling.Text

它似乎有效,因为我正在处理格式良好的 .xml 文件,其中 xyz:Region 的 previousSibling 始终是 xyz:AddressText 的最后一行,其中包含我正在寻找的 City 值。我仍然很感激任何评论,因为我仍然不知道这(以及下面的代码)是否甚至是远程有效的。我有很多大的 .xml 文件要粉碎,所以效率很重要。

我需要使用一些过时的 VB6 代码,其中包括一个递归 XML 粉碎子例程。我对VB6很熟悉,但是我不明白这个子程序。我在下面粘贴了一部分代码。我希望有人可以向我指出一些详细的背景阅读材料,这些材料将帮助我弄清楚这个子例程的 XML 处理方面是如何工作的,以便我可以维护和修改它。我还在下面粘贴了我需要使用的两个 XML 文件的 [已清理] 示例摘录。一个问题是地址的城市部分存储在一系列枚举属性的最后一个中。要获取 City,我需要从具有最大 xyz:sequenceNumber 值的属性中提取文本。SO有很多帖子,其中包含如何获得最高价值属性的示例,但我可以' t 让他们在这个子程序中工作。通常,它们似乎使用了一个 max() 函数——当我尝试在这个子例程中使用它时,VB6 抱怨它;或者他们使用你在下面的片段中看到的东西,但是当我尝试适应 VB6 抱怨双冒号(“::”)。

doc.SelectSingleNode("//Employees/Employee/@Id[not(. <=../preceding-sibling::Employee/@id) and not(. <=../following-sibling::Employee/@Id)]");

我猜我看到的示例与 VB6 中可用的库不同。

这是 XML 示例:

<abc:Person>
  <xyz:LicenseNo>1234</xyz:LicenseNo>
  <xyz:Language xyz:languageCode="en">
    <xyz:Name>
      <xyz:Company xyz:languageCode="en">ABC Company Ltd.</xyz:Company>
    </xyz:Name>
    <xyz:AddressCollection>
      <xyz:Address>
        <xyz:SequencedAddress xyz:languageCode="en">
          <xyz:AddressText xyz:sequenceNumber="1">The ABC Building</xyz:AddressText>
          <xyz:AddressText xyz:sequenceNumber="2">123 Main Street</xyz:AddressText>
          <xyz:AddressText xyz:sequenceNumber="3">3rd Floor</xyz:AddressText>
          <xyz:AddressText xyz:sequenceNumber="4">Tampa</xyz:AddressText>
          <xyz:Region xyz:RegionCategory=“State”&gt;FL</xyz:Region>
          <xyz:CountryCode>US</xyz:CountryCode>
          <xyz:ZipCode>33607</xyz:ZipCode>
        </xyz:SequencedAddress>
      </xyz:Address>
    </xyz:AddressCollection>
  </xyz:Language>
</abc:Person>
<abc:Person>
  <xyz:LicenseNo>567</xyz:LicenseNo>
  <xyz:Language xyz:languageCode="en">
    <xyz:Name>
      <xyz:Company xyz:languageCode="en">XYZ Industries Ltd.</xyz:Company>
    </xyz:Name>
    <xyz:AddressCollection>
      <xyz:Address>
        <xyz:SequencedAddress xyz:languageCode="en">
          <xyz:AddressText xyz:sequenceNumber="1">XYZ Factory Plaza</xyz:AddressText>
          <xyz:AddressText xyz:sequenceNumber="2">678 Elm Street</xyz:AddressText>
          <xyz:AddressText xyz:sequenceNumber="3">Orlando</xyz:AddressText>
          <xyz:Region xyz:RegionCategory=“State”&gt;FL</xyz:Region>
          <xyz:CountryCode>US</xyz:CountryCode>
          <xyz:ZipCode>32814</xyz:ZipCode>
        </xyz:SequencedAddress>
      </xyz:Address>
    </xyz:AddressCollection>
  </xyz:Language>
</abc:Person>

这是代码部分:

Public Sub ShredXML(ByRef Nodes As MSXML2.IXMLDOMNodeList)
Dim xNode As MSXML2.IXMLDOMNode

    For Each xNode In Nodes
            If xNode.nodeType = NODE_ELEMENT Then
                If xNode.nodeName = "abc:Person" Then
                tmpCompany = xNode.selectSingleNode("//abc:Person//xyz:Company").Text
                tmpLicenseNo = xNode.selectSingleNode("//abc:Person//xyz:LicenseNo").Text
                tmpLanguage = xNode.selectSingleNode("//abc:Person//xyz:Language").Attributes.getNamedItem("xyz:languageCode").Text
                tmpRegion = xNode.selectSingleNode("//abc:Person//xyz:Region").Text
                tmpCountryCode = xNode.selectSingleNode("//abc:Person//xyz:CountryCode").Text
                tmpZipCode = xNode.selectSingleNode("//abc:Person//xyz:ZipCode").Text

‘ database insert code omitted

                End If
            End If

        If xNode.hasChildNodes Then
            ShredXML xNode.childNodes
        End If

   Next xNode
4

1 回答 1

0
于 2018-10-31T14:19:48.450 回答