glfnute 0 Newbie Poster

I am struggling with how to parse the following XML document. I need to "walk" through the nodes via the Rank attribute (asc) with 2 rules:

1. Keep a running copy of what the Channel is so I can compare it to the next node in the list

2. In the event of 2 nodes with the same Rank, the compare would be between the two nodes of the same Rank.

Sample input:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
    <SalesTerrChk/>
    <row>
        <SiteType>M</SiteType>
        <Type>P</Type>
        <DWHSalesTerritoryID>4</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYJ</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEI</SiteID>
        <Channel>VS</Channel>
        <StartDate>2008-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>1</Rank>
        <Delete/>
        <Update/>
    </row> - <row>
        <SiteType>D</SiteType>
        <Type>P</Type>
        <DWHSalesTerritoryID>10</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYG</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEO</SiteID>
        <Channel/>
        <StartDate>2009-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>2</Rank>
        <Delete/>
        <Update/>
    </row> - <row>
        <SiteType>M</SiteType>
        <Type>C</Type>
        <DWHSalesTerritoryID>3</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYF</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEI</SiteID>
        <Channel>BT</Channel>
        <StartDate>2010-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>3</Rank>
        <Delete/>
        <Update/>
    </row> - <row>
        <SiteType>D</SiteType>
        <Type>P</Type>
        <DWHSalesTerritoryID>13</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYO</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEO</SiteID>
        <Channel>BT</Channel>
        <StartDate>2010-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>3</Rank>
        <Delete/>
        <Update/>
    </row> - <row>
        <SiteType>D</SiteType>
        <Type>C</Type>
        <DWHSalesTerritoryID>16</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYL</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEO</SiteID>
        <Channel/>
        <StartDate>2011-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>5</Rank>
        <Delete/>
        <Update/>
    </row> - <row>
        <SiteType>M</SiteType>
        <Type>F</Type>
        <DWHSalesTerritoryID>5</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYK</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEI</SiteID>
        <Channel>VS</Channel>
        <StartDate>2012-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>6</Rank>
        <Delete/>
        <Update/>
    </row>
</rows>

and the sample output would look like:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
    <SalesTerrChk>Check passed</SalesTerrChk>
    <row>
        <SiteType>M</SiteType>
        <Type>P</Type>
        <DWHSalesTerritoryID>4</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYJ</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEI</SiteID>
        <Channel>VS</Channel>
        <StartDate>2008-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>1</Rank>
        <Delete/>
        <Update/>
    </row>
    - <row>
        <SiteType>D</SiteType>
        <Type>P</Type>
        <DWHSalesTerritoryID>10</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYG</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEO</SiteID>
        <Channel/>
        <StartDate>2009-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>2</Rank>
        <Delete>true</Delete>
        <Update/>
    </row>
    - <row>
        <SiteType>M</SiteType>
        <Type>C</Type>
        <DWHSalesTerritoryID>3</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYF</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEI</SiteID>
        <Channel>BT</Channel>
        <StartDate>2010-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>3</Rank>
        <Delete/>
        <Update/>
    </row>
    - <row>
        <SiteType>D</SiteType>
        <Type>P</Type>
        <DWHSalesTerritoryID>13</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYO</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEO</SiteID>
        <Channel>BT</Channel>
        <StartDate>2010-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>3</Rank>
        <Delete>true</Delete>
        <Update/>
    </row>
    - <row>
        <SiteType>D</SiteType>
        <Type>C</Type>
        <DWHSalesTerritoryID>16</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYL</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEO</SiteID>
        <Channel/>
        <StartDate>2011-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>5</Rank>
        <Delete>true</Delete>
        <Update/>
    </row>
    - <row>
        <SiteType>M</SiteType>
        <Type>F</Type>
        <DWHSalesTerritoryID>5</DWHSalesTerritoryID>
        <SalesTerrRowID>ADOA-4VHJYK</SalesTerrRowID>
        <SiteID>ADOA-3ZVNEI</SiteID>
        <Channel>VS</Channel>
        <StartDate>2012-01-01T00:00:00.000</StartDate>
        <Brand>-</Brand>
        <Rank>6</Rank>
        <Delete/>
        <Update/>
    </row>
</rows>

If I am able to traverse this structure, I can set the global SalesTerritoryChk attribute as well as the Delete/Update fields. Any advice or direction would be greatly appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.