View Single Post
 
Old November 7th, 2007, 08:58 AM
vishnu108mishra vishnu108mishra is offline
Authorized User
 
Join Date: Nov 2007
Location: Allahabad, UP, India.
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to append child node after an node in XML + C#

Hello every
I need a help for writing xml elements. Can any one help me how we repeat a whole chile node with attributes, how can I repeat <FieldToSupport> whole block After the </SupportItems> block

---------------------------------------------------------
This is my XML file structure

<?xml version="1.0" encoding="utf-8"?>
<LinkInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <LinkToolId>0</LinkToolId>
  <LinkToolVersion>1.0.1</LinkToolVersion>
  <ScreensToSupport>
    <ScreenToSupport>
      <ScreenUniqueId>c1f13323-209b-4b0e-ad8d-d34f64d34c28</ScreenUniqueId>
<SupportItems>
        <LinkURL>C:\Documents and Settings\Login Subhash\Desktop\iframe.html</LinkURL>
        <LinkText>New Link Help</LinkText>
        <ScreenSupportItem>
          <LinkDate>2007-10-25T11:47:10.515625+05:30</LinkDate>
          <LinkAuthor>SUBHASH\Login Subhash</LinkAuthor>
          <LinkURL>C:\Documents and Settings\Login Subhash\Desktop\main.html</LinkURL>
          <LinkText>Adding New Html Help</LinkText>
          <OptionalSupportInstruction />
          <RefId>3</RefId>
        </ScreenSupportItem>
</SupportItems>
<FieldsToSupport>
        <LinkURL>C:\Documents and Settings\Login Subhash\Desktop\iframe.html</LinkURL>
        <LinkText>New Link Help</LinkText>
        <FieldToSupport>
          <Caption>Blank</Caption>
          <Url>Blank</Url>
          <Label>NewField1</Label>
          <HtmlName />
          <HtmlId />
          <FieldUniqueId>15b85c2b-83ca-44ec-8741-22a4dc64f64d</FieldUniqueId>
          <LinkHref>http://careers.msn.com/</LinkHref>
          <InnerHTML>Careers &amp;amp; Jobs</InnerHTML>
          <OuterHTML>&lt;A href="http://careers.msn.com"&gt;Careers &amp;amp; Jobs&lt;/A&gt;</OuterHTML>
          <PopupHTML />
          <FieldSupportItems />
        </FieldToSupport>
<FieldToSupport>
..
</FieldToSupport>
<FieldToSupport>
..
</FieldToSupport>
</FieldsToSupport>
      <Label>label3</Label>
      <ScreenMatchProbabilityLevel>172.0934</ScreenMatchProbabilityLevel>
    </ScreenToSupport>
  </ScreensToSupport>
</LinkInformation>
---------------------------------------------------------
This is my sample code in which I repeat the <LinkURl> and <LinkText> field.
but I have to now repeat whole <SupportItems> tags
How can I did this pls any one can response me. I will very thankful for that.
---------------------------------------------------------
This is my sample code


if (strAlbumName != "" && strAlbumPath != "")
            {
                strXMLFile = strAlbumPath + "\\" + strAlbumName + ".linkinfo.xml";
                XmlDocument doc = new XmlDocument();
                doc.Load(strXMLFile);

                System.Data.DataSet objDataSet = new DataSet();

                FileStream findata = new FileStream(strXMLFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                objDataSet.ReadXml(findata);
                findata.Close();
                //int intRefId = Convert.ToInt32(Request.QueryString["RefId"]);
                int intRefId = 3;
                string strFilePath = FileUpload.PostedFile.FileName;
                string strXPath = "/LinkInformation/ScreensToSupport/ScreenToSupport/SupportItems/ScreenSupportItem[RefId='" + intRefId + "']";

                XmlNode newParent = doc.SelectSingleNode(strXPath);

                foreach (System.Xml.XmlNode node in newParent)
                {
                    if (node.Name == "LinkURL")
                    {
                        if (node.InnerText == FileUpload.PostedFile.FileName)
                        {
                            BaydonConstants.flag = true;
                            break;
                        }
                    }
                    else if (node.Name == "LinkText")
                    {
                        if (node.InnerText == txtUrlTitle.Text)
                        {
                            BaydonConstants.flag = true;
                            break;
                        }
                    }
                }
                if (BaydonConstants.flag)
                {
                    lblError.Text = "LinkURL/LinkText already exist !";
                    BaydonConstants.flag = false;
                }
                else
                {
                    XmlNode newSibling = newParent["LinkAuthor"];
                    XmlElement newLinkURL = doc.CreateElement("LinkURL");
                    XmlElement newLinkText = doc.CreateElement("LinkText");
                    newLinkText.InnerText = txtUrlTitle.Text;
                    newLinkURL.InnerText = FileUpload.PostedFile.FileName;
                    newParent.InsertAfter(newLinkURL, newSibling);
                    newParent.InsertAfter(newLinkText, newLinkURL);
                    doc.Save(strXMLFile);
                    lblError.Text = "Inserted Successfully !";
                }
            }
        }
-----------------------------------------------------------