Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 12, 2009 10:41 AM by Martin_Honnen
Member
4 Points
2 Posts
Dec 11, 2009 08:44 PM|LINK
hello I am new in this topic and even trying to replicate the code in the post i do not manage.
I try with this code and
IEnumerable<XElement> rootCategory = test.Root.Elements("productItems");
foreach (XElement productItemTest in rootCategory.Elements("productItem"))
{
//first of all the productItemTest looks like is empty and not assigned but i have more than 2000 productITem in the xml
//and in addition here i would like to copy somehow and i am not sure how all fields inside each productItem
}
my xml file has this format.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <response xmlns="http://mytest.com"> <page>0</page> <items>5</items> <total>86999</total> <query>auto</query> <productItems> <productItem id="b41ef4142dd453af3ecec7536d106000"><name>yyy</name><link>http://...</link>...</productItem> <productItem id="e812451eaef9c300652e6ac02d04a611">...</productItem> <productItem id="fded6e2f02c74c0acae48f6ec4b7c711">...</productItem> <productItem id="d50523c267e0cb3ccd7767c989eb49ea">...</productItem> <productItem id="659e30d5a8b40dc08cf83ab8659b17a4">...</productItem> </productItems> </response>
Star
14481 Points
2006 Posts
MVP
Dec 12, 2009 10:41 AM|LINK
If you are new to using LINQ to XML then start by reading the documentation, either online at http://msdn.microsoft.com/en-us/library/bb387098.aspx or in your local MSDN/Visual Studio documentation.
For your XML you need to know about how to deal with namespaces in LINQ to XML:
XNamespace ns = test.Root.Name.Namespace; IEnumerable<XElement> rootCategory = test.Root.Elements(ns + "productItems"); foreach (XElement productItemTest in rootCategory.Elements(ns + "productItem")) { string id = (string)productItemTest.Attribute("id"); // ... }
frankwlp
Member
4 Points
2 Posts
Re: Reading child nodes of XDocument
Dec 11, 2009 08:44 PM|LINK
hello I am new in this topic and even trying to replicate the code in the post i do not manage.
I try with this code and
IEnumerable<XElement> rootCategory = test.Root.Elements("productItems");
foreach (XElement productItemTest in rootCategory.Elements("productItem"))
{
//first of all the productItemTest looks like is empty and not assigned but i have more than 2000 productITem in the xml
//and in addition here i would like to copy somehow and i am not sure how all fields inside each productItem
}
my xml file has this format.
<div></div>Martin_Honne...
Star
14481 Points
2006 Posts
MVP
Re: Reading child nodes of XDocument
Dec 12, 2009 10:41 AM|LINK
If you are new to using LINQ to XML then start by reading the documentation, either online at http://msdn.microsoft.com/en-us/library/bb387098.aspx or in your local MSDN/Visual Studio documentation.
For your XML you need to know about how to deal with namespaces in LINQ to XML:
XNamespace ns = test.Root.Name.Namespace; IEnumerable<XElement> rootCategory = test.Root.Elements(ns + "productItems"); foreach (XElement productItemTest in rootCategory.Elements(ns + "productItem")) { string id = (string)productItemTest.Attribute("id"); // ... }My blog