'Resolve Cross-Referenced XML

So, using the first generic example below, I'd like to remove the 'book' section and place it under 'bookInfo' using the attribute 'bookID' to link it to the ssid of the books like the second exmple.

EXAMPLE1


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<example-list list-type="whole-list" date="2022-03-25">
    <library ssid="1">
        <name>Generic Library Number 1</name>
        <shelf ssid="2">
            <shelfName>A4<shelfName>
            <row ssid="3">
                <rowLocation>1st shelf<rowLocation>
                <bookInfo ssid="9" bookID="545" />
            </row>
            <row ssid="5">
                <rowLocation>2nd shelf<rowLocation>
                <bookInfo ssid="10" bookID="568" />
            </row>
        </shelf>
    </library>

    <book ssid="545">
        <title>Generic Book Number 1</title>
        <type>NonFiction</type>
        <pages>123</pages>
    </booK>

    <book ssid="568">
        <title>Generic Book Number 1</title>
        <type>NonFiction</type>
        <pages>123</pages>
    </booK>
</example-list> 

EXAMPLE2

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<example-list list-type="whole-list" date="2022-03-25">
    <library ssid="1">
        <name>Generic Library Number 1</name>
        <shelf ssid="2">
            <shelfName>A4<shelfName>
            <row ssid="3">
                <rowLocation>1st shelf<rowLocation>
                <bookInfo ssid="9" bookID="545" />
                    <book ssid="545">
                        <title>Generic Book Number 1</title>
                        <type>NonFiction</type>
                        <pages>123</pages>
                    </booK>
            </row>
            <row ssid="5">
                <rowLocation>2nd shelf<rowLocation>
                <bookInfo ssid="10" bookID="568" />
                    <book ssid="568">
                        <title>Generic Book Number 1</title>
                        <type>NonFiction</type>
                        <pages>123</pages>
                    </booK>
            </row>
        </shelf>
    </library>
</example-list>

The best way I could think of to do it is to create a list of the book nodes in the library nodes whenever a bookID is encountered. But I can't help but think that there has to be a better method and/or some prebuilt tool to de-reference an XML, even though I couldn't find that tool in my own searching.

I'm currently working on a C# program to do what I need to for a specific XML file which has 7305 nodes that are cross-referenced sometimes multiple times. I'm hoping this question either points me in a smart direction to solve this or shows me a tool that I hadn't seen to quickly get through this problem.

Thank you for your time.



Sources

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

Source: Stack Overflow

Solution Source