我試圖理解需要使用一些VB.net代碼寫入數據庫的XML的大數據轉儲。我正在尋找解析代碼入門的一些幫助,特別是如何訪問屬性值。用VB.net解析XML
<Product ID="523233" UserTypeID="Property" ParentID="523232">
<Name>My Property Name</Name>
<AssetCrossReference AssetID="173501" Type=" Non Print old">
</AssetCrossReference>
<AssetCrossReference AssetID="554740" Type=" Non Print old">
</AssetCrossReference>
<AssetCrossReference AssetID="566495" Type=" Non Print old">
</AssetCrossReference>
<AssetCrossReference AssetID="553014" Type="Non Print">
</AssetCrossReference>
<AssetCrossReference AssetID="553015" Type="Non Print">
</AssetCrossReference>
<AssetCrossReference AssetID="553016" Type="Non Print">
</AssetCrossReference>
<AssetCrossReference AssetID="553017" Type="Non Print">
</AssetCrossReference>
<AssetCrossReference AssetID="553018" Type="Non Print">
</AssetCrossReference>
<Values>
<Value AttributeID="5115">Section of main pool</Value>
<Value AttributeID="5137">114 apartments, four floors, no lifts</Value>
<Value AttributeID="5170">Property location</Value>
<Value AttributeID="5164">2 key</Value>
<Value AttributeID="5134">A comfortable property, the apartment is set on a pine-covered hillside - a scenic and peaceful location.</Value>
<Value AttributeID="5200">PROPERTY_ID</Value>
<Value AttributeID="5148">facilities include X,Y,Z</Value>
<Value AttributeID="5067">Self Catering. </Value>
<Value AttributeID="5221">Frequent organised daytime activities</Value>
</Values>
</Product>
</Product>
基本上我想在具有特定屬性ID的xml文件中找到屬性。所以它會像下面列出的代碼一樣,這是我對它應該是什麼的解釋。該代碼不起作用,所以我會在某處出錯。
這是相關行,我需要能夠訪問:
<Value AttributeID="5200">PROPERTY_ID</Value>
Dim productsXML As XElement = XElement.Load("C:\myFile.xml")
Dim foundNode As XElement
Dim query = From p In productsXML.Elements("Product").Descendants("Values") Where p.Attributes("attribute").ToString = "PROPERTY_ID"
foundNode = query.FirstOrDefault()
我能找到一個單獨的節點使用下面的代碼,但我需要找出一種方法來遍歷屬性值所以我可以將它們讀入一個對象。 昏暗productsXML作爲的XElement = XElement.Load(XMLFILE) 昏暗ParentNode作爲的XElement 昏暗ChildNode作爲的XElement 昏暗查詢=從p在productsXML ... _ 凡p.Value = 「PROPERTY_ID」 ParentNode =查詢。 FirstOrDefault() –
SuperFurryToad
2010-04-06 20:10:47