Solved

How to deletw Rows with duplicate data element?

Posted on 2011-03-10
5
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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