Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

How to deletw Rows with duplicate data element?

Hello,

How do I delete rows with duplicate Child in my xml file? For example if my xml file contains

<Row>
<Item>1</Item>
<Child>1</Child>1
</Row>
<Row>
<Item>2</Item>
<Child>1</Child>1
</Row>
<Row>
<Item>3</Item>
<Child>2</Child>1
</Row>
<Row>
<Item>4</Item>
<Child>1</Child>1
</Row>

I would like to create a new xml file with the following data (removing Rows with duplicate Child)


<Row>
<Item>1</Item>
<Child>1</Child>1
</Row>
<Row>
<Item>3</Item>
<Child>2</Child>1
</Row>

I am uding VB.NET (VS2010)
Thanks,

Victor
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

You could use a simple XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">
<xsl:key name="row" match="Row" use="Child"/>
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="Row[generate-id() = generate-id(key('row', Child)[1])]">
        <xsl:copy-of select="."/>
    </xsl:template>
    <xsl:template match="Row[not(generate-id() = generate-id(key('row', Child)[1]))]"/>
</xsl:stylesheet>

Open in new window

Avatar of Victor  Charles

ASKER

Sorry,

I'm lost, how do i incoporate this code in VB.NET? What do i need to import in my project to use this code? How do you create the new xml file without duplicate?

Thanks,

Victor
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.