首页 / XML / 如何直接在C#中调用嵌套的xml元素
如何直接在C#中调用嵌套的xml元素
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何直接在C#中调用嵌套的xml元素,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2676字,纯文字阅读大概需要4分钟。
内容图文
这是我的xml …
<CruiseProduct>
<ID>4091</ID>
<Name>MS ROYAL RUBY NILE CRUISE</Name>
<Description>
<p><br>In house music panel.<br>Safe deposit box.<br>All modern and high quality installation and amenities.<br><br><br><b>All inclusive formula</b><br>Breakfast open buffet<br>Lunch open buffet<br>dinner open buffet<br>From 11.00 AM till 23.00 HRS<br>Water (Small Bottle)<br>Soft drinks<br>Local beer (Served by glass)<br>Local wine (Only during lunch and dinner)</p><p><br><b><b>The Program includes:</b><br></b>? 07 nights’ accommodation on board of MS Royal Ruby or Similar based on Full Board<br>? Return airport transfers in Luxor using Shuttle services<br>? Guaranteed upgrade to Main / Middle deck cabins.<br>? Complimentary Luxor city tour<b><br><br><b>The Program excludes:</b><br></b>? Entry visa to Egypt<br>? Tips and personal expenses<br>? Any other items did not mentioned above</p><p><b><br></b></p><p><b>Attraction - Combo Light Package</b><br>Visit to the east Bank, Karnak and Luxor temples, Visit the Temple shared by two gods Sobek and Haeroris in Kom Ombo afternoon, Morning visit to High dam, Phila temple<br><b><br>Attraction - Combo Full Package Excursions</b><br>Visit to the East Bank, Karnak and Luxor temples, Visit the Temple shared by two gods Sobek and Haeroris in Kom Ombo afternoon, Visit Edfu Temple, Morning visit to High dam, Philae temple and unfinished obelisk, on return visits West bank, Hatsheput, Valley of the Kings, Memmon colossi Esna Temple<br><br><b>Attraction - Cruise Signature Program</b><br>Visit Dier-al-Madina + Habu Temple + Valley of the Nobles, Dendra Temple by bus + Temple of Hathor-Cript, Edfu OR Kom Ombo Temple (up to the customer) Kalabsha trip + Botanical Gardens + 01 hour felucca </p>
</Description>
<Ref>CMBRUB</Ref>
<Location>Luxor</Location>
<Images>
<Image>
<Name>MS Royal Ruby</Name>
<Description/>
<URL>
http://banks.digital-trip.co.uk/assets/images/packages/c228fa2c-18b1-4c93- 9edc-aa3409d07b7b.jpg
</URL>
</Image>
这是我的代码….
var product = from a in cruiseDoc.Descendants("CruiseProduct")
select new CProducts
{
cruise_Id = a.Element("ID").Value,
cruise_Name = a.Element("Name").Value,
cruise_description= a.Element("Description").Value,
// cruise_Imagerurl = a.Descendants("")
};
var newProduct = product.ToArray();
ViewBag.Lengths = newProduct;
我想立即调用成像器URL元素,并在cruise_Imageurl变量中分配其值.
希望你的帮助
解决方法:
现在我们知道您只需要第一个Image元素,这很简单:
cruise_Imagerurl = a.Element("Images").Element("Image").Element("URL").Value
请注意,这假设始终至少有一张图像.如果不是这种情况,您可能需要:
cruise_Imagerurl = (string) a.Elements("Images")
.Elements("Image")
.Elements("URL")
.FirstOrDefault()
内容总结
以上是互联网集市为您收集整理的如何直接在C#中调用嵌套的xml元素全部内容,希望文章能够帮你解决如何直接在C#中调用嵌套的xml元素所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。