Quantcast
Viewing latest article 1
Browse Latest Browse All 4

XML help needed

Hi It_s Meee;

To your question, "What is i want to get the reference base on attribute", You need to find the node that has the Attribute which you want to find and use that as the reference node.

To you question, "i want to get the reference on <time id = 2> ", assuming the original XML document one of the following queries will do what you want.

// Use this query if only one date node is in the document the number 2 // can be a variable in the program.
XElement timeNode = (from time in xdoc.Root.Element("city").Element("date").Elements("time")where (int) time.Attribute("id") == 2select time).FirstOrDefault ();// Use this query if the document can have more then one date node. // The date string and the 2 can be variables in the program
XElement timeNode = (from date in xdoc.Root.Element("city").Elements("date")where (string) date.Attribute("value") == "02.06.2006"from time in date.Elements("time")where (int) time.Attribute("id") == 2select time).FirstOrDefault ();

The end result the variable timeNode holds the time node you are looking for or null if none. is found

 


Fernando

If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

Viewing latest article 1
Browse Latest Browse All 4

Trending Articles