Removing child and putting it back - InfoPath Dev
in

InfoPath Dev

Removing child and putting it back

Last post 05-02-2007 09:02 AM by Matt Faus. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 10-30-2006 11:09 AM

    • djay
    • Top 500 Contributor
    • Joined on 06-06-2006
    • Posts 35

    Removing child and putting it back

    Using C# I am trying to pull a section of XML out of the main data source, do work on it and putting it back. I'm doing this for speed reasons, when I do the work while it is still in the main data source it takes ten times as long. But under a certain circumstance the data structure I put back in is not correct. Here is what it's doing:
    Say I have a starting XML of:

    <Grandparent>
    <Parent>
    <Child>Kid1</Child>
    <Child>Kid2</Child>
    <Child>Kid3</Child>
    <Child>Kid4</Child>
    </Parent>
    </Grandparent>


    In code I have IXMLDOMNode objects associated with Grandparent and Parent, so I pull out the Parent object to do work on it.

    Grandparent.removeChild(Parent);

    Then I remove the child "Kid2" and when I look at it with the debugger Parent looks like this:
    <Parent>
    <Child>Kid1</Child>
    <Child>Kid3</Child>
    <Child>Kid4</Child>
    </Parent>


    Then I add it back into Grandparent:

    Grandparent.appendChild(Parent);

    And when I look at it XML now it looks like this:
    <Grandparent>
    <Parent>
    <Child>Kid1</Child>
    <Child>Kid2</Child>
    <Child>Kid3</Child>
    </Parent>
    <Grandparent>


    And when I look at Parent in the debugger it has changed during the append to the new data.
    Also, if I do the work without removing Parent first (by commenting out the remove and append lines) it works perfectly.
    What is going on here?

    BTW-I have tried this with cloning Parent at the top and using replaceChild at the end and I still get the same problem.

    Anyone have any suggestions?

    Thanks,
    -Dan
  • 05-02-2007 09:02 AM In reply to

    Re: Removing child and putting it back

    Hi Dan,

    Sorry for the late reply. This seems incredibly weird, but I think I might have run into something like this before. My suggestion would be to use replaceChild(), but you said it gave you the same error. Since the objects are failing you, you should edit the XML string directly. Instead of calling insertChild() or replaceChild() on Grandparent, simply do Grandparent.xml = "...";

    I hope this helps!
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.