Solved

How to deletw Rows with duplicate data element?

Posted on 2011-03-10
5
265 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:vcharles
  • 3
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35093955
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

0
 

Author Comment

by:vcharles
ID: 35093980
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
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 35094114
There are a zillion articles out there that explain how to run an XSLT in VB.Net

I list a few here that seem correct to me
Note that you need to save the XSLT as a sepêrate file and I assume that you might allready have the XML as an object

http://www.vbdotnetheaven.com/UploadFile/Globalking/xmlxslt108112006012217AM/xmlxslt1.aspx
http://stackoverflow.com/questions/1187782/vb-net-apply-xsl-transformation-to-xml-file
0
 

Author Comment

by:vcharles
ID: 35094159
Thanks.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35157957
welcome
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now