-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: rags_rao
Message 2 in Discussion

heere u go.......... select ID,Text from tablename......... should give u xml <root>
<tablename ID="1"  Text ="Sample\Store\M\3" />
<tablename ID="1"  Text ="Sample\Store\M" />
<tablename ID="1"  Text ="Sample\Store\M\1" />
<tablename ID="1"  Text ="Sample\Store\M\2" />
<tablename ID="2"  Text ="Sample\Time\2" />
<tablename ID="2"  Text ="Sample\Time" />
<tablename ID="2"  Text ="Sample\Time\1" />
</root>   using System.Xml;
using System.IO;
using System.Text.RegularExpressions; class XXX
{
 public static void Main()
 {
   XmlDocument xmlDoc = new XmlDocument();
   //xmlDoc.LoadXml("<root><tablename ID="1"  Text ="Sample\Store\M\3" /><tablename 
ID="1"  Text ="Sample\Store\M" /><tablename ID="1"  Text ="Sample\Store\M\1" 
/><tablename ID="1"  Text ="Sample\Store\M\2" /><tablename ID="2"  Text ="Sample\Time" 
/><tablename ID="2"  Text ="Sample\Time\1" /></root>");
   xmlDoc.Load(@"xml.xml");
//   StringWriter sw;
//   XmlTextWriter xmlWrite = new XmlTextWriter(sw = new StringWriter());
//   xmlWrite.WriteStartElement("Treenode");
   XmlDocument xmlDoc1 = new XmlDocument();
   xmlDoc1.LoadXml("<Treenode/>");
   XmlNodeList records = xmlDoc.DocumentElement.ChildNodes;
   for(int i=0;i<records.Count;)
   {
    XmlNode  curRec = records[i];
    string /*text = curRec.Attributes["Text"],*/id=curRec.Attributes["ID"].Value;
    Add(xmlDoc,xmlDoc1,id/*,text*/);
    //XmlElement newNode = xmlDoc1.CreateElement("treenode");
    //newNode.SetAttribute("text",curRec.Attributes["Text"]);
   }
   xmlDoc1.Save(@"out.xml");
 }
 public static void Add(XmlDocument docFrom,XmlDocument docTo,string id/*,string 
text*/)
  {
   XmlNodeList nodeList = docFrom.SelectNodes("root/[EMAIL PROTECTED]'"+id+"']");
   //i'm assuming text is unique and has the pattern x,x/1,x/2,x/3
   string [] text = new string[nodeList.Count];
   foreach(XmlNode curNode in nodeList)
   {
    string curText = curNode.Attributes["Text"].Value;
    Match match = Regex.Match(curText,"\\\\\\d+$");
    int index = 0;
    if(match.Success) index = int.Parse(match.Value.Substring(1));
    text[index] = curText;
    docFrom.DocumentElement.RemoveChild(curNode);
   }
   
   XmlNode parentNode = docTo.DocumentElement;
   foreach(string str in text)
   {
    XmlElement newNode = docTo.CreateElement("treenode");
    newNode.SetAttribute("text",str);
    parentNode.AppendChild(newNode);
    parentNode = newNode;
   }
  }
} o/p: <Treenode>
  <treenode text="Sample\Store\M">
    <treenode text="Sample\Store\M\1">
      <treenode text="Sample\Store\M\2">
        <treenode text="Sample\Store\M\3" />
      </treenode>
    </treenode>
  </treenode>
  <treenode text="Sample\Time">
    <treenode text="Sample\Time\1">
      <treenode text="Sample\Time\2" />
    </treenode>
  </treenode>
</Treenode>  

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to