0

根据我的研究,我已经能够在 VBA 中构建一个函数来解析 XML 并根据需要公开值。但是,有一个价值让我无法理解。

<osgb:topographicMember>
     <osgb:TopographicArea fid='osgb1000000347753568'>
     <osgb:featureCode>10053</osgb:featureCode>
     <osgb:version>4</osgb:version>
     <osgb:versionDate>2006-03-15</osgb:versionDate>
     <osgb:theme>Land</osgb:theme>
     <osgb:calculatedAreaValue>46.099150</osgb:calculatedAreaValue>
     <osgb:changeHistory>
         <osgb:changeDate>2001-03-09</osgb:changeDate>
         <osgb:reasonForChange>New</osgb:reasonForChange>
     </osgb:changeHistory>
     <osgb:descriptiveGroup>General Surface</osgb:descriptiveGroup>
     <osgb:descriptiveTerm>Multi Surface</osgb:descriptiveTerm>
     <osgb:make>Multiple</osgb:make>
     <osgb:physicalLevel>50</osgb:physicalLevel>
     <osgb:polygon><gml:Polygon srsName='osgb:BNG'>
     <gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>290996.130,92420.290   290998.010,92415.010 291000.000,92415.720 291005.770,92417.770 291003.890,92423.040 291000.000,92421.660 290996.130,92420.290 </gml:coordinates>
     </gml:LinearRing>
     </gml:outerBoundaryIs>
     </gml:Polygon>
     </osgb:polygon></osgb:TopographicArea>
     </osgb:topographicMember>

我试图获得的值是 fid = 'osgb10000000347753568'

我可以获取并返回 TopographicArea (using xChild.baseName) ,但不是 fid。

欢迎任何想法!

4

1 回答 1

0

如果我正确理解输入,您需要打开TopographicAreanode 并获取其Fid属性.text.NodeValue属性(取决于节点数据类型,以最适合的为准)而不是 node .baseName,即您应该使用以下内容:

Set XMLDOC = CreateObject("MSXML2.DOMDocument")
.....
Set SubNode = XMLDOC.SelectNodes("//[list of parent nodes]/topographicMember/TopographicArea/")
fid = SubNode.Attributes.Item(0).NodeValue

也许我的表示法有误,但这里你应该使用的关键点.text还是.NodeValue属性。添加的 XMLDOC 的 VBA 监视窗口将非常有帮助。祝你好运!

于 2013-02-02T11:04:01.957 回答