Odczytywanie Atrybutow x XML

0

Witam, ktos moze mi powiedziec gdzie popelnilem blad? Probowalem juz chyba wszystkie mozliwosci bez efektu.
Potrzebuje odczytac atrybut, ktory nie zawsze wystepuje w kazdym <Products>
oto moj kod:

            XmlDocument doc = new XmlDocument();
            doc.Load(filepath);

            XmlNodeList xnList = doc.GetElementsByTagName("Products");

            glSQL sql = new glSQL();

            foreach (XmlNode xn in xnList)
            {
                XmlElement amount = (XmlElement)xn;
                string sku = amount.GetElementsByTagName("SKU")[0].InnerText;
                string ean = amount.GetElementsByTagName("EAN")[0].InnerText;
                string description = amount.GetElementsByTagName("Description")[0].InnerText;
                var att = amount.Attributes["Gross Weight"];
                string weight = "0.00";
                if (att != null)
                {
                    weight = amount.Attributes["Gross Weight"].Value;
                }

                sql.updateVipInventory(ean, sku, description, weight);
                sql.addVipToInventory(ean, description, "2", sku);
                Console.WriteLine("SKU: " + sku + " description: {0}", description + " Weight: " + weight);
            } 

a oto przyklad XML:

 
<ProductCatalog xmlns="">
  <Products>
    <ProdID>8424</ProdID>
    <SKU>4118</SKU>
    <Description>CORSAIR 1GB DDR2 533 SO-DIMM</Description>
    <Manufacturer>CORSAIR</Manufacturer>
    <ManufacturersPartNumber>VS1GSDS533D2</ManufacturersPartNumber>
    <ProductGroup>Memory</ProductGroup>
    <ProductImage>ftp://images:[email protected]/11078.jpg</ProductImage>
    <EAN>870584005179</EAN>
    <Attributes>
      <ProdID>8424</ProdID>
      <SKU>4118</SKU>
      <AttributeName>Gross Weight</AttributeName>
      <AttributeValue>0.20Kg</AttributeValue>
    </Attributes>
</ProductCatalog>
1

Mała podpowiedź w tym xmlu nie ma ani jednego atrybutu. Jest tylko element o nazwie Attributes. ;)

0

to by w sumie duzo wyjasnialo. Dzieki :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1