how add/update Element with same name as other

I have xml file with following data.

<actor>
<name>Actor Name 1</name>
<type>Actor</type>
<thumb>image.jpg</thumb>
</actor>

<actor>
<name>Actor Name 2</name>
<type>Actor</type>
<thumb>image.jpg</thumb>
</actor>

<genre>genre1</genre>
<genre>genre2</genre>

 

I would like to compare existing genre and actors in xml file with value i have to see if they already exited if not add/remove/update them.

If I do update the actor name then i would like to remove the image of the actor from the xml

$file = New-Object System.Xml.XmlDocument
$file.Load($file_path)

$file_data.genre

$file_data.actor.name

but i dont know how to compare or update date in nested element

Hi Lalajee,

Your post is quite vague and I’m not sure what you’re trying to accomplish. Hopefully this example will help. Otherwise, please add more details. :slight_smile:

function Show-Actors{
    "";"----------------- $($args[0]) Actors -----------------"
    $file.data.actor
}

$file = [xml]@'
<?xml version="1.0"?>
<data>
    <actor>
        <name>Actor Name 1</name>
        <type>Actor</type>
        <thumb>image.jpg</thumb>
    </actor>

    <actor>
        <name>Actor Name 2</name>
        <type>Actor</type>
        <thumb>image.jpg</thumb>
    </actor>

    <genre>genre1</genre>
    <genre>genre2</genre>
</data>
'@

Show-Actors Original

foreach($actor in $file.data.actor)
{
    If($actor.name -eq 'Actor Name 2')
    {
        $actor.name = "New Actor Name"
        $actor.thumb = ""
    }
}

Show-Actors Updated

What i want to do is check the actors in my xml file and company then with new actors which in arary to say if actors already in xml or not if not then add them but if the actor existed in xml but not in arrary then remove them from xml

Same thing for genre