从XML文档中提取值 [英] Extract Value from XML Document
本文介绍了从XML文档中提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我正在粗略地从XML文档中提取节点值。 我觉得我很亲密,但不能完全理解,所以我诉诸论坛。 我习惯于处理SQL 服务器 数据,所以
这对我来说是新的。 请在下面找到我的代码和XML数据。 提前致谢!
Hello all I am having a rough time extracting a node value from an XML Document. I feel like I am close, but cannot quite figure it out so I have resorted to the forums. I am used to dealing with SQL Server Data so
this is new to me. Please find my code and XML data below. Thanks in advance!
<?xml version="1.0" encoding="utf-8"?>
<RETS ReplyCode="0" ReplyText="Operation successful">
<RETS-RESPONSE xmlns="CREA.Search.Property">
<Pagination>
<TotalRecords>961</TotalRecords>
<Limit>10</Limit>
<Offset>1</Offset>
<TotalPages>97</TotalPages>
<RecordsReturned>10</RecordsReturned>
</Pagination>
<PropertyDetails ID="11937196" LastUpdated="Thu, 14 Jun 2012 16:39:57 GMT">
<ListingID>DDF106RES001</ListingID>
<AgentDetails ID="1937465">
<Name>Alex Drow</Name>
<Office ID="270564">
<Name>Consumer Housing Inc.</Name>
<Address>
<City>Kentville</City>
</Address>
</Office>
<Position>Broker Owner</Position>
</AgentDetails>
<Board>106</Board>
<Business>
<Franchise>False</Franchise>
</Business>
<Building>
<BathroomTotal>2</BathroomTotal>
<BedroomsTotal>3</BedroomsTotal>
<CoolingType>Central air conditioning</CoolingType>
<DisplayAsYears>2</DisplayAsYears>
<FireplacePresent>False</FireplacePresent>
<HeatingFuel>Natural gas</HeatingFuel>
<HeatingType>Air circulation heat</HeatingType>
<SizeInterior>1685 sqft</SizeInterior>
<Type>House</Type>
</Building>
</PropertyDetails>
</RETS-RESPONSE></RESPONSE>
$
Dim xnList As XmlNodeList = document.SelectNodes("RETS/RETS-RESPONSE/PropertyDetails")
For Each xn As XmlNode In xnList
Dim example As XmlNode = xn.SelectSingleNode("Building")
If example IsNot Nothing Then
Dim na As String = example("BathroomTotal").InnerText
Dim no As String = example("BathroomTotal").InnerText
End If
Next
推荐答案
希望这有助于开始
Hope this helps as start
Dim objDoc As XmlDocument = New XmlDocument()
objDoc.Load("yourxml")
Dim xn = objDoc.GetElementsByTagName("Building")
For Each example As XmlNode In xn
If example IsNot Nothing Then
Dim na As String = example("BathroomTotal").InnerText
Dim no As String = example("BathroomTotal").InnerText
End If
Next
这篇关于从XML文档中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文