login about faq

Hi. Please help me. GetChild - return only odd nodes. All OK when comment line: xmlC->AddChildTree( *child )

    int testAddChildTree()
    {
        CkXml xmlSource;    
        xmlSource.LoadXml( "<a><b>1</b><b>2</b><b>3</b><b>4</b>\
                            <b>5</b><b>6</b><b>7</b><b>8</b></a>");
        xmlSource.GetRoot2();

        CkXml xmlDest;
        xmlDest.put_Tag("a");
        CkXml* xmlC = xmlDest.NewChild("C","");

        int iCount = xmlSource.get_NumChildren();
        printf("get_NumChildren: %d\n", iCount);

        for (int i = 0; i < iCount; i++ )
        {
            CkXml* child = xmlSource.GetChild(i);
            if (child)
            {
                printf("%d: %s\n", i, child->content() );
                xmlC->AddChildTree( *child );
                delete child;
            }
        }
        delete xmlC;

        printf("%s\n", xmlDest.xml());

        return 0;
    }

Output:

get_NumChildren: 8
0: 1
1: 3
2: 5
3: 7
<?xml version="1.0" encoding="utf-8" ?>
<a>
    <C>
        <b>1</b>
        <b>3</b>
        <b>5</b>
        <b>7</b>
    </C>
</a>

asked Aug 05 '13 at 19:10

iserbin's gravatar image

iserbin
1111


What happens if you do not delete the child while looping through the XMLSource?

link

answered Aug 12 '13 at 21:27

mpiacentini's gravatar image

mpiacentini
1111

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×7

Asked: Aug 05 '13 at 19:10

Seen: 1,429 times

Last updated: Aug 12 '13 at 21:27

powered by OSQA