2

have an XML file like this:

<VS>
  <Fields>
    <Field Id="$1*">Column1</Field>
    <Field Id="$2*">Column2</Field>
    <Field Id="$3*">Column3</Field>
  </Fields>
</VS>

When I use LINQ to XML using the following statement:

 XDocument doc = XDocument.Parse(s);
var q = doc.Descendants("Fields").ToList();

I get a single entry in list as Column1Column2Column3, whereas I want it as 3 separate entities like Column1, Column2, Column3.

Can anyone help?

3 Answers 3

4

Use Field instead of Fields:

var q = doc.Descendants("Field").ToList();
Sign up to request clarification or add additional context in comments.

Comments

0

you should use XElement.Parse(BuildNode.InnerXml) instead of just passing the raw property in.

Check This

Comments

0

Just used the following code which returned list of strings.

var q = doc.Descendants("Field").Select(x => x.Value);

Thanks for all your suggestions!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.