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
Solved

How to deletw Rows with duplicate data element?

Posted on 2011-03-10
5
272 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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