Chastia® | Portals - chastia.eu - prevody.sk - aspnet.sk - termoklima.sk - Partners - Quantasoft - QSH.sk - Free Web Hosting
 
WUG.sk udalosti
WebSlice - FórumDiskusné fórum
Vyhľadávanie
Skip Navigation LinksAspNet.sk > F�rum > .NET > Web Forms (ASP.NET)

Diskusné fórum

Autor Téma
jakub
12. 3. 2010 12:23:06
Príspevkov: 655
Článkov: 0
Blogy: 0
Správičiek: 0
Body: 3275

Najaktívnejší č.: 8
linq xml
ako vytiahnut z xml <productcategoryitem>
<Products>
<ProductItem>
<ProductCode>1024</ProductCode>
<ProductCategories>
<ProductCategoryItem>xxx&gt;Foto a video&gt;Čistenie a údržba&gt;Ochrana displeja</ProductCategoryItem>
</ProductCategories>
</ProductItem>
var tutorials = from tutorial in xmlDoc.Descendants("Products")
                            select
new
                            
{
                                a
= tutorial.Element("productCode").Value,
                                b
= tutorial.Element("productcategoryitem").Value, //tu je chyba
                              

                            }
;


jakub

Bookmark and Share [Reakcia]
T
12. 3. 2010 13:27:38
Príspevkov: 1654
Článkov: 0
Blogy: 42
Správičiek: 162
Body: 13610

Najaktívnejší č.: 3
RE: linq xml
var products=
from
node
in xDoc.Element("Products").Elements("ProductItem")
select
new
{
Code
= node.Element("ProductCode").Value,
Categories
=
(
from
category
in node.Elements("ProductCategories").Elements("ProductCategoryItem")
select
category.Value
).ToList()
}
;

Tomáš Zeman, MCSD.NET

Bookmark and Share [Reakcia]
jakub
12. 3. 2010 15:28:37
Príspevkov: 655
Článkov: 0
Blogy: 0
Správičiek: 0
Body: 3275

Najaktívnejší č.: 8
RE: linq xml
snazim sa nacitat zaznamy z xml suboru do tabulky no berie iba prvy
zaznam aj ked by malo nacitat
2 zaznamy, ide o subor ,ktory ma az 26 MB teda asi 10000 zaznamov a tieto potrebujem importnut z xml do tabulky mssql


public class Tutorial
       
{
           public
string a { get; set; }
          
// public string b { get; set; }
          // public decimal c { get; set; }
       }


       public
void Button3_Click(object sender, System.EventArgs e)
       
{


           try
           
{



           string soubor1
=
Server.MapPath(
"~/data/zhraj/xml/testa.xml");//
Server.MapPath("test.xml");
           XDocument xmlDoc
= XDocument.Load(soubor1);
           string txttconn
=
System.Configuration.ConfigurationManager.AppSettings[
"myconnection"];


           var tutorials
= from tutorial in xmlDoc.Descendants("PriceList")
                           select
new
                           
{
                               a
=
tutorial.Element(
"Products").Element("ProductItem").Element("ProductName").Value,


                           }
;

           SqlConnection conn
= new SqlConnection(txttconn);
           conn.Open();

           foreach (var tutorial
in tutorials)
           
{

               Response.Write(
"a");
               var p
= tutorial.a;
             
/* var k = tutorial.b;
               var d = tutorial.c;
*/

               Response.Write(p);
               SqlCommand cmd
= new SqlCommand("INSERT INTO TESTA<br />(name) values (@a)", conn);<br />               SqlParameterCollection sqlParams = cmd.Parameters;
               sqlParams.Add(
@"a", SqlDbType.VarChar).Value=p;

               cmd.ExecuteNonQuery();
           }
;
           conn.Close();
           }
</span>
xml version="1.0" encoding="Utf-8" ?>
- <PriceList version="1.0" application="Shop" note="" xmlns="">
- <Products>
- <ProductItem>
  
<ProductCode>1024</ProductCode>
  
<ProductName>1024 Display Protection Foil Displex Protector, 3.0</ProductName>
  
<ProductType>HAMA</ProductType>
  
<Availability>DE</Availability>
  
<PriceDmoc>10,84</PriceDmoc>
  
<Price>5,85</Price>
  
<MinimalOrder>0</MinimalOrder>
  
<Bestseller>False</Bestseller>
  
<News>False</News>
  
<Bargain>False</Bargain>
  
<Discount>False</Discount>
  
<Action>False</Action>
  
<PriceUp>False</PriceUp>
  
<NoDiscount>False</NoDiscount>
  
<ProductAlternates />
- <ProductCategories>
  
<ProductCategoryItem>HAMA>Foto a video>Čistenie a údržba>Ochrana displeja</ProductCategoryItem>
  
</ProductCategories>
  
<ProductInventory>0</ProductInventory>
  
<ProductEan>4007249010247</ProductEan>
  
<ProductHeight>23,40</ProductHeight>
  
<ProductWidth>0,20</ProductWidth>
  
<ProductLength>9,60</ProductLength>
  
<ProductWeight>15,500</ProductWeight>
  
<ProductPackQuantity>25</ProductPackQuantity>
  
<MasterCartonHeight>20,00</MasterCartonHeight>
  
<MasterCartonWidth>40,00</MasterCartonWidth>
  
<MasterCartonLength>57,00</MasterCartonLength>
  
<MasterCartonWeight>7750,000</MasterCartonWeight>
  
<MasterCartonQuantity>500,00</MasterCartonQuantity>
  
<PalletQuantity>3000</PalletQuantity>
- <ProductPictures>
- <ProductPictureItem>
  
<ProductPictureMain>http://www.hama.sk/ProductImages/00001/abs/00001024abs.jpg
  <ProductPictureThumb>http://www.hama.sk/ProductImages/00001/abt/00001024abt.jpg
  <ProductPictureDetail>http://www.hama.sk/ProductImages/00001/abb/00001024abb.jpg
  </ProductPictureItem>
  
</ProductPictures>
  
</ProductItem>
- <ProductItem>
  
<ProductCode>1052</ProductCode>
  
<ProductName>1052 DIARÁMČEKY DSR 1,6 200 KS</ProductName>
  
<ProductType>HAMA</ProductType>
  
<Availability>DE</Availability>
  
<PriceDmoc>23,36</PriceDmoc>
  
<Price>13,00</Price>
  
<MinimalOrder>0</MinimalOrder>
  
<Bestseller>False</Bestseller>
  
<News>False</News>
  
<Bargain>False</Bargain>
  
<Discount>False</Discount>
  
<Action>False</Action>
  
<PriceUp>False</PriceUp>
  
<NoDiscount>False</NoDiscount>
  
<ProductAlternates />
- <ProductCategories>
  
<ProductCategoryItem>HAMA>Foto a video>Dia>Dia rámčeky</ProductCategoryItem>
  
</ProductCategories>
  
<ProductInventory>0</ProductInventory>
  
<ProductEan>4007249010520</ProductEan>
  
<ProductHeight>16,50</ProductHeight>
  
<ProductWidth>5,50</ProductWidth>
  
<ProductLength>10,30</ProductLength>
  
<ProductWeight>502,000</ProductWeight>
  
<ProductPackQuantity>1</ProductPackQuantity>
  
<MasterCartonHeight>16,60</MasterCartonHeight>
  
<MasterCartonWidth>27,50</MasterCartonWidth>
  
<MasterCartonLength>52,00</MasterCartonLength>
  
<MasterCartonWeight>12878,000</MasterCartonWeight>
  
<MasterCartonQuantity>25,00</MasterCartonQuantity>
  
<PalletQuantity>750</PalletQuantity>
- <ProductPictures>
- <ProductPictureItem>
  
<ProductPictureThumb>http://www.hama.sk/ProductImages/00001/abt/00001052abt.jpg
  <ProductPictureDetail>http://www.hama.sk/ProductImages/00001/abb/00001052abb.jpg
  </ProductPictureItem>
  
</ProductPictures>
  
</ProductItem>
  
</Products>
  
</PriceList>

jakub

Bookmark and Share [Reakcia]
T
12. 3. 2010 20:38:30
Príspevkov: 1654
Článkov: 0
Blogy: 42
Správičiek: 162
Body: 13610

Najaktívnejší č.: 3
RE: linq xml
Ahoj,

je to preto, lebo
xmlDoc.Descendants("PriceList") je prave jeden node, nie zoznam.


Pozri si moj priklad.

rychly fix toho Tvojho kodu je takyto

xmlDoc.Descendants("ProductItem") a potom len Element("ProductName").Value

robis len jednorazovy import?

Tomáš Zeman, MCSD.NET

Bookmark and Share [Reakcia]


Zdroje
Bloggeri OPML Bloggeri
RSS 100 SpigiBlog
RSS 3 EX©M
RSS 1 singh
WUG.sk články
WUG.sk
Najaktívnejší...
28605 b. 1. vlko
14160 b. 2. spigi
13610 b. 3. T
4045 b. 4. duracellko
3845 b. 5. slavof
3460 b. 6. siro
3295 b. 7. skippo
3275 b. 8. jakub
2595 b. 9. dudok
2145 b. 10. ex
Ocenenie

MVP Profil - Igor Stanek
Čo je to MVP?
Partneri portálu
Reklama
Spriatelené weby
Copyright © 2002 - 2009 Chastia, spol. s r. o., Igor Stanek, Designed by Lacino
Portál je hostovaný na serveroch firmy Quantasoft - www.qsh.sk.
RSS - anotácia, RSS - Blogy