View Single Post
 
Old November 8th, 2007, 01:57 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

Hello sir I have tried it but its not working according to my requirement. I have to create a new child <ScreenSupportItem> below the parent node <SupportItems> with matching condition --where attribute of <ScreenSupportItem> e.g <RefId> is equal to 3 (comes from query string). Also new <ScreenSupportItem> child have different attributes except <RefId>. So I have to create a <ScreenSupportItem> with setting new values of all the attributes.

This is the structure of XML file
-----------------------------------------------------------------
<?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>
    ........all have same structure <ScreenToSupport>
    </ScreenToSupport>
    <ScreenToSupport>
    ........all have same structure <ScreenToSupport>
    </ScreenToSupport>
    <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>
    <ScreenToSupport>
    ........all have same structure <ScreenToSupport>
    </ScreenToSupport>
  </ScreensToSupport>
</LinkInformation>
-----------------------------------------------------------------
And this is my sample code
-----------------------------------------------------------------
strXMLFile = strAlbumPath + "\\" + strAlbumName + ".linkinfo.xml";
                XmlDocument doc = new XmlDocument();
                doc.Load(strXMLFile);
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);//.ParentNode.NextSibling.ChildNodes;

                XmlNode newRootParent = doc.SelectSingleNode(strXPath).ParentNode;

                XmlNode newScreenToSupport = newParent.Clone();
                newRootParent.InsertAfter(newRootParent, newScreenToSupport);
                doc.Save(strXMLFile);
-----------------------------------------------------------------
It giving error 'ERROR:Cannot insert a node or any ancestor of that node as a child of itself.'
I am very new in xml please help me to solved my problem. I will very thankful for your valuable cooporation.
Please reply me soon....