how to get item based on item code from xml file?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi All,
I have an xml file as shown, need to get the necessary item based on item code passed.
<pre class="prettyprint <Items>

<Shirt Code="TRC001
<Name>3D-Tshirt-Blue</Name>
<Description>3D-Tshirt-Blue</Description>
<ItemType>Shirt</ItemType>
<Size>38</Size>
<ImgType>3d</ImgType>
<ImgResource>ImagesImages_3DResources3DShirt_Resource_Blue.png</ImgResource>
<ImgUrl>ImagesImages_3DShirts3DShirt_2DImg_Blue.png</ImgUrl>
<Scale3D>0.35</Scale3D>
<Width>0</Width>
<Height>0</Height>
<DefaultVerticalOffset>0.7</DefaultVerticalOffset>
<DefaultHorizontalOffset>0</DefaultHorizontalOffset>
<DefaultScalingFactor>1</DefaultScalingFactor>
</Shirt>
<Shirt Code="TRC002
<Name>3D-Tshirt-Green</Name>
<Description>3D-Tshirt-Green</Description>
<ItemType>Shirt</ItemType>
<Size>38</Size>
<ImgType>3d</ImgType>
<ImgResource>ImagesImages_3DResources3DShirt_Resource_Green.png</ImgResource>
<ImgUrl>ImagesImages_3DShirts3DShirt_2DImg_Green.png</ImgUrl>
<Scale3D>0.35</Scale3D>
<Width>0</Width>
<Height>0</Height>
<DefaultVerticalOffset>0.7</DefaultVerticalOffset>
<DefaultHorizontalOffset>0</DefaultHorizontalOffset>
<DefaultScalingFactor>1</DefaultScalingFactor>
</Shirt>
<Pant Code="PP001
<Name>Light Cement Colored Pant</Name>
<Description>Light Cement Colored Pant</Description>
<ItemType>Pant</ItemType>
<Size>38</Size>
<ImgType>2d</ImgType>
<ImgResource>None</ImgResource>
<ImgUrl>ImagesImages_2DPantsLight Cement Pant.png</ImgUrl>
<Scale3D>0</Scale3D>
<Width>100</Width>
<Height>250</Height>
<DefaultVerticalOffset>0</DefaultVerticalOffset>
<DefaultHorizontalOffset>0</DefaultHorizontalOffset>
<DefaultScalingFactor>1</DefaultScalingFactor>
</Pant>
<Goggle Code="GG001
<Name>Rayban Glasses</Name>
<Description>Rayban Glasses</Description>
<ItemType>Goggle</ItemType>
<Size>38</Size>
<ImgType>2d</ImgType>
<ImgResource>None</ImgResource>
<ImgUrl>ImagesImages_2DGogglesRayban Glasses.png</ImgUrl>
<Scale3D>0</Scale3D>
<Width>50</Width>
<Height>30</Height>
<DefaultVerticalOffset>-10</DefaultVerticalOffset>
<DefaultHorizontalOffset>0</DefaultHorizontalOffset>
<DefaultScalingFactor>1</DefaultScalingFactor>
</Goggle>
</Items>[/code]
I wrote something like this, but couldnt get the item. Can anyone help me here?
<pre class="prettyprint object objItem = Utility.GetItem(btnItemCode)<span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small <span style="font-size:small <pre class="prettyprint public static Object GetItem(string itemCode)
{
XDocument data = XDocument.Load("Database.xml");
return (from item in data.Descendants("Items")
//where item.Attribute("Code").Value == itemCode
where item.Element("Code").Value == itemCode
select new
{
Code = item.Attribute("Code").Value,
Name = item.Element("Name").Value,
Description = item.Element("Description").Value,
ItemType = item.Element("ItemType").Value,
Size = item.Element("Size").Value,
ImgType = item.Element("ImgType").Value,
ImgResource = Common.globalImagePath + item.Element("ImgResource").Value,
ImgUrl = Common.globalImagePath + item.Element("ImgUrl").Value,
Scale3D = Convert.ToDouble(item.Element("Scale3D").Value),
Height = Convert.ToDouble(item.Element("Height").Value),
Width = Convert.ToDouble(item.Element("Width").Value),
DefaultVerticalOffset = Convert.ToDouble(item.Element("DefaultVerticalOffset").Value),
DefaultHorizontalOffset = Convert.ToDouble(item.Element("DefaultHorizontalOffset").Value),
DefaultScalingFactor = Convert.ToDouble(item.Element("DefaultScalingFactor").Value)
}).FirstOrDefault();
}[/code][/code]
<a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a> <a>

View the full article
 
Back
Top