Please Help me how to Read the values of ActionBody,ActionSubject
using XPath.
Here First i have to Filter beased on ModuleName/ModuleID and Second I have to Filter Based on
ActionID/ActionName and finally i have to select the values of
ActionBody and ActionSubject
<div>Hello bvpavan:)</div> <div>If there's an xelement under the root of every node "ModuleAction"——You can do this easily with the help of LINQ-TO-XML——And then bind the result to GridView or something else……(not an expert in XSLT,but this should also help)。</div>
<div>
var result = from e in XDocument.Load("xxx.xml").Descedants("ModuleAction")
select new
{
ActionBody = e.Element("ActionBody").Value,
ActionSubject = e.Element("ActionSubject").Value
};
bvpavan
Member
74 Points
39 Posts
Reading XML File data
Jan 27, 2012 06:11 AM|LINK
Hi,
I have a XML File having data like
<edate>
<Modules ModuleID="1" ModuleName="Module1">
<ModuleAction ActionID="1" ActionName="Action1">
<ActionBody> //ActionBody......... </ActionBody>
<ActionSubject> //ActionSubject....</ActionSubject>
</Modules>
</edata>
Please Help me how to Read the values of ActionBody,ActionSubject using XPath.
Here First i have to Filter beased on ModuleName/ModuleID and Second I have to Filter Based on ActionID/ActionName and finally i have to select the values of ActionBody and ActionSubject
Thanks in Advance.....
Pavan Kumar B.V
xpath
johnypwalker
Member
131 Points
52 Posts
Re: Reading XML File data
Jan 27, 2012 06:39 AM|LINK
hi please check these tutorial
http://support.microsoft.com/kb/307548
http://www.codeproject.com/Articles/4902/Reading-an-XML-file-using-NET
check this solved thread
http://forums.asp.net/t/1322024.aspx/1
bvpavan
Member
74 Points
39 Posts
Re: Reading XML File data
Jan 27, 2012 07:44 AM|LINK
All these Examples are Explaning the Filtering or Reading Beased on eaither node1 or value like these structure...
<Root>
<Node1>
<Node2> Value2 </Node2>
<Node3> Value3 </Node3>
</Node11>
</Root>
Here i want filter senario id different....
Any how thanks for the reply....
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Reading XML File data
Jan 29, 2012 12:57 AM|LINK
var result = from e in XDocument.Load("xxx.xml").Descedants("ModuleAction") select new { ActionBody = e.Element("ActionBody").Value, ActionSubject = e.Element("ActionSubject").Value };</div>bvpavan
Member
74 Points
39 Posts
Re: Reading XML File data
Jan 30, 2012 03:57 AM|LINK
Thanks Decker....
I Can try this,..But iam new to LINQ...
I did this like
XmlNodeList xnList1 = doc.SelectNodes("//Modules[@moduleName='" + _ModuleName + "']");
foreach (XmlNode xn in xnList1)
{
XmlNodeList xnList2 = doc.SelectNodes("//moduleAction[@actionName='" + _ActionName + "']");
foreach (XmlNode xn1 in xnList2)
{
strSubject = xn1["subject"].InnerText;
strMailBody = xn1["body"].InnerText;
}
}
iam getting the result,..but this is not correct way to approch...
Can anybody help me ?...
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Reading XML File data
Jan 30, 2012 04:13 AM|LINK
Hello bvpavan:)
Thanks for your feedback and in fact I've offered your codes,you can paste and have a try first。
Then what you are using isn't LINQ-TO-XML but a general XmlDocument……So you can have a try like this following:
1)Your xml isn't right,please change to this following:
2)Then code like what I've showed to you:
bvpavan
Member
74 Points
39 Posts
Re: Reading XML File data
Jan 30, 2012 04:50 AM|LINK
Hi Decker,
Thanks for the solution..... Iam getting the Result...But i have a dought like is this the correct way to approch ?
Please let me know if there is any Effecient way to do...
anyhow Thanks Decker :)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Reading XML File data
Jan 30, 2012 05:05 AM|LINK
Use XDocument (LINQ-TO-XML) instead……
I'm afraid you can only use this,if for coding with XmlDocument or XDocument……
bvpavan
Member
74 Points
39 Posts
Re: Reading XML File data
Jan 30, 2012 08:41 AM|LINK
Hi Decker,
Can you tell me how to capture ActionID after Second Loop.
bvpavan
Member
74 Points
39 Posts
Re: Reading XML File data
Jan 30, 2012 09:16 AM|LINK
Hi Decker i got it
strActionID = xn1.Attributes["ActionID"].Value;