How to retrieve value from attribute in XML?

botka

New Member
What I have:\[code\]<?xml version="1.0" encoding="Unicode" standalone="yes"?><FiberItems> <Fiber China="1a" England="1b" Japan="1c" France="1d" Korea="1e"/> <Fiber China="2a" England="2b" Japan="2c" France="2d" Korea="2e"/></FiberItems>\[/code\]What I want:
1.retrive all the value of "China" into a string array.
2.if a value of China is "1a", retrive all the value of the rest attributes(1b,1c,1d,1e),.
What I do:
1. I write codes for purpose 1 , but never works >_<\[code\] XDocument doc = XDocument.Load("/FiberItems.xml"); IEnumerable<string> query = from fiber in doc.Root.Elements("Fiber") select (string)fiber.Attribute("China"); string[] myString = new string[3]; for (int i = 0; i < 3; i++) { foreach (string item in query) { myString = (string)item; } }\[/code\]2. for purpose 2, have no idea yet >_<need helps
 
Back
Top