0

我希望有一个我正在寻找的简单答案,但我已经搜索了几个小时,似乎找不到答案。另外,我坚持使用经典的 asp。我只需要获取此 XML 结构的第一个元素的文本。

 <section href="multifamily">For Multifamily 
   <item href="resources.htm">Resources</item> 
   <item href="vacancy-rates">Rental Vacancy Rates</item> 
   <item href="multiFamily-update">Multifamily Update Newsletter</item> 
 </section>

由于某种原因,我在循环浏览整个 XML 文件时无法获取文本“Multifamily”。

这是我到目前为止的一些代码:

Sub findName(xmlObject)

Set sections = objXMLDoc.SelectNodes(XMLObject.ObjType)
countSections(sections)

End Sub

Sub countSections(sections)

Response.write(sections.length)
If sections.length > 1 Then
    putInArray(sections)
End IF
End Sub

Sub putInArray(sections)
Dim section

''For Each section In sections
''  Response.write(section.innerText)
''Next
For i = 0 To sections.length -1
    Response.write(sections.item(0).text)
Next

End Sub

我真的很感激任何和所有的帮助。

4

2 回答 2

0

I figured out the answer, which as I suppected was something I was overlooking. Here is the answer in case someone else has the same question:

For i=0 To ObjNodes.length -1
    Response.write(ObjNodes(i).firstChild.text &"<br />")

Next

I just needed to grab the first child instead of all the children. I hope this helps someone else in the future.

于 2014-07-10T15:13:23.707 回答
0

看起来 XML 无效。您可以在节点或文本中拥有节点......不能两者兼而有之。您需要将“For Multifamily”放在节点中或将其用作属性。例如

<section href="multifamily">
  <newnode>For Multifamily </newnode>
  <item href="resources.htm">Resources</item> 
  <item href="vacancy-rates">Rental Vacancy Rates</item> 
  <item href="multiFamily-update">Multifamily Update Newsletter</item> 
</section>

或者

<section href="multifamily" newattribute="For Multifamily">
  <item href="resources.htm">Resources</item> 
  <item href="vacancy-rates">Rental Vacancy Rates</item> 
  <item href="multiFamily-update">Multifamily Update Newsletter</item> 
</section>
于 2014-07-10T04:43:26.933 回答