'Updating XML via XDocument with Linq C#

I'm using XDocument in C# to manipulate a more elaborate version of the below XML document. I'm trying to check if the 'part-no' element value is 99999 for each part. If the value is 99999, I want to swap out the entire part element for a new part element I have stored in string variable.

<statement>   
    <header>
        <created>5/3/2022</created>        
        <charges>100.00</charges>        
        <description>some text</description>
        <billing-party>
            <name>3304</name>
            <address>1703</address>
            <phone />
        </billing-party>      
    </header>    
    <invoices>
        <invoice>
            <invoice-no>39D5</invoice-no>
            <line-items>
                <line-item>
                    <line-no>1</line-no>                    
                    <parts>
                        <part>
                            <part-no>990303</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                        <part>
                            <part-no>890304</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                    </parts>                    
                    <part-number>139186</part-number>
                </line-item>
                <line-item>
                    <line-no>2</line-no>                    
                    <parts>
                        <part>
                            <part-no>990303</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                        <part>
                            <part-no>890304</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                    </parts>                    
                    <part-number>139186</part-number>
                </line-item>
                <line-item>
                    <line-no>1</line-no>                    
                    <parts>
                        <part>
                            <part-no>990303</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                        <part>
                            <part-no>890304</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                    </parts>                    
                    <part-number>139186</part-number>
                </line-item>               
            </line-items>
        </invoice>
        <invoice>
            <invoice-no>39D5</invoice-no>
            <line-items>
                <line-item>
                    <line-no>1</line-no>                    
                    <parts>
                        <part>
                            <part-no>990303</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                        <part>
                            <part-no>890304</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                    </parts>                    
                    <part-number>139186</part-number>
                </line-item>
                <line-item>
                    <line-no>2</line-no>                    
                    <parts>
                        <part>
                            <part-no>990303</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                        <part>
                            <part-no>890304</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                    </parts>                    
                    <part-number>139186</part-number>
                </line-item>
                <line-item>
                    <line-no>1</line-no>                    
                    <parts>
                        <part>
                            <part-no>99999</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                        <part>
                            <part-no>890304</part-no>
                            <description>
                               some description
                            </description>
                            <tax />
                            <value>270.50</value>
                            <quantity />                            
                        </part>
                    </parts>                    
                    <part-number>139186</part-number>
                </line-item>               
            </line-items>
        </invoice>
    </invoices>
</statement>

Using linq, what is the best way to do this without creating a new XDocument?

I tried this but I'm new to linq and don't quite understand how to achieve this without using FirstOrDefault().

statementFile.ReplaceNodes(

                from invoice in statementFile.Descendants("invoices")
                from lineItem in invoice.Descendants("line-items")
                from part in lineItem.Descendants("parts")
                where part.Element("part-no").Value.Equals("99999")
                select part.ReplaceWith(updatedPart));    
                );


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source