0

I was using below code when my XML has a single element of 'HTTPSamplerProxy' now I have multiple elements with the same name and I want all to store.

XElement HTTPSamplerProxy = doc.Descendants("HTTPSamplerProxy").FirstOrDefault();
        path = (string)HTTPSamplerProxy.Elements("stringProp").Where(x => (string)x.Attribute("name") == "HTTPSampler.path").FirstOrDefault();
        domain = (string)HTTPSamplerProxy.Elements("stringProp").Where(x => (string)x.Attribute("name") == "HTTPSampler.domain").FirstOrDefault();
        method = (string)HTTPSamplerProxy.Elements("stringProp").Where(x => (string)x.Attribute("name") == "HTTPSampler.method").FirstOrDefault();
1

1 Answer 1

0

Your method Descendants returns already a collection of node HTTPSamplerProxy.

So just eliminate FirstOrDefault, get the collection and loop for each node.

IEnumerable<XElement> proxies = doc.Descendants("HTTPSamplerProxy");

foreach(var proxy in proxies)
{
}
Sign up to request clarification or add additional context in comments.

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.