使用LINQ to XML创建XML文件 [英] creating XML file with LINQ to XML

查看:100
本文介绍了使用LINQ to XML创建XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将linq写入此类以下xml数据的xml查询

I need to write linq to xml query of such kind of below xml data

<PRODUCT>
<ID>34169</ID>
<D1>good</D1>
<D2>well</D2>
<L1>lame</L1>
<L2>killer</L2>
<BR>IOMEGA</BR>
<KDV>18</KDV>
<IMG>34169.JPG</IMG>
<EAN>data1</EAN>
<ATP>50+</ATP>
<DM3>0,51</DM3>
<S>
  <L>Tip</L>
  <V>HARICI</V>
</S>
<S>
  <L>Renk</L>
  <V>METALIK GRI</V>
</S>
<S>
  <L>Kapasite (GB)</L>
  <V>500</V>
</S>
<S>
  <L>Dönüş Hızı (Rpm)</L>
  <V>5400,0</V>
</S>
<S>
  <L>Arabirim</L>
  <V>USB 2.0</V>
</S>
<S>
  <L>Form Faktörü (Inch)</L>
  <V>2,5</V>
</S>
<S>
  <L>Ön Bellek (Kb/mb)</L>
  <V>8,0</V>
</S>
<S>
  <L>Satış Garanti Süresi (ay)</L>
  <V>36</V>
</S>

我的问题是

  1. 仅获取第一张图像 是中的几张图片 database(img包含 图片作为我数据库中的字符串 表格)

  1. get only the first image when there is several images in the database(img holds the path of an image as a string in my database table)

处理<S>部分

我是LINQ to XML的新手,请帮助,谢谢.

I am new to LINQ to XML please help, thanks.

推荐答案

有我的答案

 XElement productCatalog = 
                   new XElement("PRODUCTCATALOG",

                               from urun in db.TBLP1URUNs
                               select new XElement("PRODUCT",

                                           new XElement("ID", urun.ID),

                                           new XElement("D1", urun.MODEL),

                                           new XElement("D2", urun.URUNACIKLAMA),

                                           new XElement("L1", urun.TBLP1URUNKATEGORI.TREENAME),

                                           new XElement("IMG", db.TBLP1URUNRESIMs.Where(p => p.URUN_ID == urun.ID).First().FILE_NAME),

                                           new XElement("EAN", urun.STOKKODU),

                                           new XElement("ATP", GetUrunStokById(urun.ID)),//STOKMIKTARI

                                           new XElement("DM3", urun.DESI),

                                           from ozellikler in urun.TBLP1OZELLIK_URUNs
                                           select new XElement("S",

                                               new XElement("L", ozellikler.TBLP1OZELLIK.TBLP1OZELLIKTIPI.TIPI),

                                               new XElement("V", ozellikler.TBLP1OZELLIK.OZELLIK))

                                               )                           
                            );

这篇关于使用LINQ to XML创建XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆