c# - XML Parsing with same tag -


i need

  1. "enter user name", "enter password"
  2. "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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -