c# - XML Parsing with same tag -
i need
- "enter user name", "enter password"
- "stack@gmail.com" / "abcd*"
in separate lists
<steps id="0" last="3"> <step id="1" type="validatestep"> <parameterizedstring><text>enter user name</text></parameterizedstring> <parameterizedstring><text>stack@gmail.com</text></parameterizedstring> <description> </description> </step> <step id="2" type="validatestep"> <parameterizedstring><text>enterpassword</text> </parameterizedstring> <parameterizedstring><text>abcd*</text></parameterizedstring> <description></description></step> <step id="3" type="actionstep"> <parameterizedstring> <text>click on login button</text> </parameterizedstring><parameterizedstring /> <description /> </step> </steps>
xdocument doc = xdocument.parse(xmlsteps); var values = (from f in doc.elements().descendants() select f.attribute("text").value).toarray();
assuming want step 1 & 2 (otherwise remove line comment), use similar this:
var values = doc.descendants("step") .where(step => new[] { "1", "2" }.contains(step.attribute("id").value)) //only step 1 & 2 .select(step => step.descendants("text").select(text => text.value).tolist());
Comments
Post a Comment