Help with creating new xml file bassed on mstching partial string using VB.NET

Hi,

  If file1 contains the following data:

  <Root>
  <Table>
  <ID>1</ID>
  <NAD>MTHH</NAD>
 <NAS>XXXX</NAS>
  </Table>
  <Table>
  <ID>2</ID>
  <NAD>UUTH</NAD>
  <NAS>YYYY</NAS>
  </Table>
  <Table>
  <ID>3</ID>
  <NAD></NAD>
  <NAS>ZZZZ</NAS>
  </Table>
  </Root>

  How do I create File3.xml with data from File 2 for all NAS values in file1 matching NAS values in File2 and only include fields in file2 matching with file 1?

  File 2:

  <Root>
  <Table>
  <ID>1</ID>
  <NAD>FFFFF</NAD>
  <NAS>XXXX;TTTT</NAS>
  <ADG>VVVVV<AGD>
  <AKS>UUUUU<AKS>
  </Table>
  <Table>
  <ID>2</ID>
  <NAD>UUUU</NAD>
  <NAS>YYYY;HHHH</NAS>
  <ADG>VVVVV<AGD>
  <AKS>UUUUU<AKS>
  </Table>
  <Table>
  <ID>3</ID>
  <NAD>DDDD</NAD>
  <NAS>ZZZZ,YUYU;UUYU</NAS>
  <ADG>VVVVV<AGD>
  <AKS>UUUUU<AKS>
  </Table>
  <Table>
  <ID>4</ID>
  <NAD>VVVVV</NAD>
  <NAS>ZZZZ</NAS>
  <ADG>VVVVV<AGD>
  <AKS>UUUUU<AKS>
  </Table>
  <Table>
  <ID>5</ID>
  <NAD>DVFVR</NAD>
  <NAS>OOOO</NAS>
  <ADG>VVVVV<AGD>
  <AKS>UUUUU<AKS>
  </Table>
  <Table>
  <ID>6</ID>
  <NAD>TTTTT</NAD>
  <NAS>NNNN</NAS>
  <ADG>VVVVV<AGD>
  <AKS>UUUUU<AKS>
  </Table>
  </Root>

  Based on matching partial string NAS values separated by ";" in File2 the results in File3.xml should be as follows:

  <Root>
  <Table>
  <ID>1</ID>
 <NAD>FFFFF</NAD>
  <NAS>XXXX</NAS>
  </Table>
  <Table>
   <ID>2</ID>
 <NAD>UUUU</NAD>
  <NAS>YYYY</NAS>
  </Table>
  <Table>
  <ID>3</ID>
  <NAD>DDDD</NAD>
  <NAS>ZZZZ</NAS>
  </Table>
  </Root>


  Thanks,

  Victor
vcharlesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

YZlatCommented:
you could use XmlDiff tool:

http://msdn.microsoft.com/en-us/library/aa302294.aspx

For example below is a VB.NET procedure that compares two files and writes the difference into the third file. Unfortunately I am not that familiar with the utility, but given the code below it should give you a starting point:

 Private Sub CompareXml(file1 As String, file2 As String, ByVal diffFile As String)

        Dim reader1 As XmlReader = XmlReader.Create(New StringReader(file1))
        Dim reader2 As XmlReader = XmlReader.Create(New StringReader(file2))

        Dim differenceStringBuilder As New StringBuilder()

        Dim fs As New FileStream(diffFile, FileMode.Create)
        Dim diffGramWriter As XmlWriter = XmlWriter.Create(fs)

        Dim xmldiff As New XmlDiff(XmlDiffOptions.IgnoreChildOrder Or XmlDiffOptions.IgnoreNamespaces Or XmlDiffOptions.IgnorePrefixes)
        Dim bIdentical As Boolean = xmldiff.Compare(file1, file2, False, diffGramWriter)

        diffGramWriter.Close()

        ' cleaning up after we are done with the xml diff file
        File.Delete(diffFile)
    End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.