I've been trying to merge two XML files I use to build my menubar in my web application for hours, but I can't get it to work. 
I have my main XML file which looks like this:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
    <version>1.0.0</version>
    <menu>
        <Category1>
            <item>
                <id>Cake</id>
                <nr>1</nr>
                <hint>I like these</hint>
                <userlevel>5</userlevel>                
            </item>
            <item>
                <id>Cake 2</id>
                <nr>2</nr>
                <hint>I like these too, but only for me</hint>
                <userlevel>10</userlevel>               
            </item>
        <Category1>
        <Category2WithApples>
        <item>
            <id>Apple Cake</id>
            <nr>1</nr>
            <hint>Sweet</hint>
            <userlevel>5</userlevel>                
        </item>
        <item>
            <id>Rainbow Cake</id>
            <nr>2</nr>
            <hint>Mine!!</hint>
            <userlevel>10</userlevel>               
        </item>
        <Category2WithApples>
    </menu>
</root>
Now, I want each user to be able to load in his custom XML which is in the same folder as the main.xml which looks like this:
<CategoryMyOwn>
    <item>
        <id>Item in my Category</id>
        <nr>0</nr>
        <hint>Some text</hint>
        <userlevel>0</userlevel>                
    </item>
</CategoryMyOwn>
<Category1>
    <item>
        <id>Item in existing category</id>
        <nr>0</nr>
        <hint>Some text</hint>
        <userlevel>0</userlevel>                
    </item>
</Category1>    
I've tried solutions from
- http://php.net/manual/de/ref.simplexml.php
- php recursion, function doesn't return any value
- http://durgagupta.com.np/php-how-to-merge-two-simplexml-objects/
but they all do not work at all for me or just append the second file to the end of my main.xml. So, my question is, how do I properly merge the user.xml into my main.xml so it looks like this:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
    <version>1.0.0</version>
    <menu>
        <Category1>
            <item>
                <id>Cake</id>
                <nr>1</nr>
                <hint>I like these</hint>
                <userlevel>5</userlevel>                
            </item>
            <item>
                <id>Cake 2</id>
                <nr>2</nr>
                <hint>I like these too, but only for me</hint>
                <userlevel>10</userlevel>               
            </item>
            <item>
                <id>Item in existing category</id>
                <nr>0</nr>
                <hint>Some text</hint>
                <userlevel>0</userlevel>                
            </item>
        <Category1>
        <Category2WithApples>
        <item>
            <id>Apple Cake</id>
            <nr>1</nr>
            <hint>Sweet</hint>
            <userlevel>5</userlevel>                
        </item>
        <item>
            <id>Rainbow Cake</id>
            <nr>2</nr>
            <hint>Mine!!</hint>
            <userlevel>10</userlevel>               
        </item>
        <Category2WithApples>
        <CategoryMyOwn>
            <item>
                <id>Item in my Category</id>
                <nr>0</nr>
                <hint>Some text</hint>
                <userlevel>0</userlevel>                
            </item>
        </CategoryMyOwn>
    </menu>
</root>
 
     
    