Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to deletw Rows with duplicate data element?

Posted on 2011-03-10
5
Medium Priority
?
279 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 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

972 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