how can I get the SQLS inside the message sign of the XML. Please help

  • Thread starter Thread starter polachan
  • Start date Start date
P

polachan

Guest
Here I have given the XML file below. I want to store the sql into the list variable

<?xml version="1.0" encoding="utf-8" ?>
<STATEMENT>
<CUSTOMER ID = "CUSTOMER1">
<SQL ID="SQLS1">
<!--
SELECT * FROM statement WHERE CODE = '123' and Invdate >= GetDate()
-->
</SQL>
<SQL ID="SQLS2">
<!--
SELECT * FROM statement WHERE CODE = '1234' and Invdate >= GetDate()
-->
</SQL>
<Address>test@gmail.com</Address>
<Address>test1@gmail.com</Address>
<Address></Address>
<MailSubject>Please find statement</MailSubject>
<MailBody>Please find statement</MailBody>

<FILENAME>file1</FILENAME>

</CUSTOMER>
<CUSTOMER ID = "CUSTOMER2">
<SQL ID="SQLS">
<!--
SELECT * FROM statement WHERE CODE = '12345' and Invdate >= GetDate()
-->

</SQL>
<Address>test@gmail.com</Address>
<Address>test1@gmail.com</Address>
<Address></Address>
<MailSubject>Please find statement</MailSubject>
<MailBody>Please find statement</MailBody>
<FILENAME>file2</FILENAME>

</CUSTOMER>
</STATEMENT>

My code is as given below

XmlNodeList subjectList = doc.GetElementsByTagName("CUSTOMER");
var result = new List<String>();

foreach (var child in subjectList)
{
if (child is XmlNode)
{
var element = (XmlNode)child;
if (element.HasChildNodes)
{
result.AddRange(GetSQL(element));
}
}
}



public static IEnumerable<string> GetSQL(XmlNode element)
{
var result = new List<String>();


foreach (var child in element.ChildNodes)
{
if (child is XmlNode)
{
var item = (XmlNode)child;
if (item.Name == "SQL")
{

result.Add(item.InnerText); // Here I want to add each sql statement inside the <!-- --!>

continue;
}
if (item.HasChildNodes)
{
result.AddRange(GetSQL(item));
}
}
}







polachan

Continue reading...
 
Back
Top