我想解析使用LINQ到Xml的以下xml文档,但我似乎无法得到任何输出。使用Linq解析XML数据到Xml
<ArrayOfCustomProperty xmlns="http://schemas.datacontract.org/2004/07/PropertySearchRestfulService.PropertySearchSoapService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<CustomProperty>
<addressLine1Field>The Boulevard,</addressLine1Field>
<addressLine2Field>Imperial Wharf</addressLine2Field>
<addressLine3Field>Fulham</addressLine3Field>
<descriptionField>This impressive penthouse apartment is arranged across two floors in the prestigious Chelsea Vista Development with numerous roof terraces with panoramic views across London. For viewing times, call to arrange your allocated appointment time.</descriptionField>
<forRentOrSaleField>Sale </forRentOrSaleField>
<furnitureField>Furnished</furnitureField>
<gardenSizeField>0</gardenSizeField>
<hasGardenField>false</hasGardenField>
<numberOfBathroomsField>5</numberOfBathroomsField>
<numberOfBedroomsField>4</numberOfBedroomsField>
<postCodeField>SW6 5TG</postCodeField>
<propertyImagesField xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:string>House1.jpg</a:string>
</propertyImagesField>
<propertyTypeField />
<rentModeField />
<rentPriceField>0</rentPriceField>
<salePriceField>267000</salePriceField>
<statusField>Available</statusField>
</CustomProperty>
下面是我试图解析XML数据
properties = from property in xmlProperty.Descendants("CustomProperty")
select new Property
{
("propertyImagesField").Value;
Description = property.Element("descriptionField").Value,
PropertyType = property.Element("propertyTypeField").Value,
AddressLine1 = property.Element("addressLine1Field").Value,
AddressLine2 = property.Element("addressLine2Field").Value,
AddressLine3 = property.Element("addressLine3Field").Value,
PostCode = property.Element("postCodeField").Value,
NumberOfBedrooms = property.Element("numberOfBedrsoomField").Value,
NumberOfBathrooms = property.Element("numberOfBathroomsField").Value,
Furniture = property.Element("furnitureField").Value,
HasGarden = property.Element("hasGardenField").Value,
GardenSize = property.Element("gardenSizeField").Value,
ForRentOrSale = property.Element("forRentOrSaleField").Value,
RentPrice = property.Element("rentPriceField").Value,
RentMode = property.Element("rentModeField").Value,
SalePrice = property.Element("salePriceField").Value,
Status = property.Element("statusField").Value
};
//的属性列表绑定到数据网格 propertyGrid.ItemsSource = properties.ToList()的方式;
任何帮助将大大appeciated。
感谢你的帮助,我刚才试过这种方法,但它通过我在我的xml文件 – 2012-03-14 20:41:17
@FrancisTchatchoua的根元素的命名空间的方式仍然不工作:是的,但其中只有一个是* default *名称空间。该代码*应该*工作。我会写一个简短但完整的程序来展示它。 – 2012-03-14 20:41:59
好的,先谢谢你,谢谢你的帮助 – 2012-03-14 20:45:30