3 Replies - 4101 Views - Last Post: 12 June 2012 - 11:42 AM Rate Topic: -----

#1 daveofgv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 06-November 08

Change XML Data - recursive multiple files

Posted 11 June 2012 - 12:46 PM

Hello all -

I would like some help on changing data in a certain tag within an XML via vb.net.

The files will be all in subforms and look like:

<?xml version="1.0" encoding="iso-8859-1"?>
<Documents xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="myxsd.xsd">
<Document Version="1.0" Name="XML Invoice" Type="Invoice" DocumentReference="" ImageReference="" CertificateReference="">
<Invoice>
<Supplier>
<Name>DDD Air Conditioning</Name>
<Identifier />
<Number>12345678</Number>
<Description />
<CorporateGroupNumber />
<POBox />
<Street />
<StreetSupplement />
<PostalCode />
<City />
<CountryCode />
<CountryName />
<TelephoneNumber />
<FaxNumber />
<VATRegistrationNumber />

Which I will need the <Number> tag changed to SAAOCR. The only problem is that there are other <Number> tags within the XML that cannot be changed (<Buyer> tag), but all <Number> tags can be changed in the <Invoice> tag - which there are multiple throughout the XML and not just in the begining. (see above)

The code I am using now:

 Dim MyXML As New XmlDocument()
        'MyXML.Load(My.Settings.XMLPath)

        ProgressBar1.Value = 10
        ' MyXML.Load("C:\Users\myuser\Desktop\New folder (3)\54_80199366_345614993\80199366_345614993_EquipmentLog.xml")
                MyXML.Load("M:\XMLs\\20120608\Second Try\20120608\61_FileNumber_341333374\341333374_Receipts.xml61_SAPOCR_341333374\341333374_Invoice.xml")

       
        

        Dim MyXMLNode As XmlNode = MyXML.SelectSingleNode("Documents/Document/Invoice/Supplier/Number")

        If MyXMLNode IsNot Nothing Then

            MyXMLNode.ChildNodes(0).InnerText = (My.Settings.XMLData)

        Else

            'Do whatever 

        End If ' Save the Xml.
        'MyXML.Save(My.Settings.XMLDESTPATH)

        ProgressBar1.Value = 40
        MyXML.Save("M:\XMLs\\20120608\Second Try\20120608\61_FileNumber_341333374\341333374_Receipts.xml")



        ProgressBar1.Value = 100
        MessageBox.Show("Element inside the XML's have been renamed")

    End Sub



The code I am using now can only do 1 xml at a time and I have 1700 to process. As you can see
(Dim MyXMLNode As XmlNode = MyXML.SelectSingleNode("Documents/Document/Invoice/Supplier/Number")


fixes the first tag, however, there are multiple.

Does anyone know either how to do this or already know of a program that can?

In summary -

multiple tags need to be changed in the <Number> tag within all <Supplier> tags.

Thanks in advanced

daveofgv

Is This A Good Question/Topic? 0
  • +

Replies To: Change XML Data - recursive multiple files

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1067
  • View blog
  • Posts: 4,174
  • Joined: 02-July 08

Re: Change XML Data - recursive multiple files

Posted 11 June 2012 - 07:48 PM

I'm curious as to why this is not a database. It would be much easier to maintain.
Was This Post Helpful? 0
  • +
  • -

#3 daveofgv  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 06-November 08

Re: Change XML Data - recursive multiple files

Posted 12 June 2012 - 09:34 AM

To be honest, the only reason why I am not using a database is because I don't know how (and didn't know I could). :)

do you have an example (or know of one) that uses a database so I can review?

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1067
  • View blog
  • Posts: 4,174
  • Joined: 02-July 08

Re: Change XML Data - recursive multiple files

Posted 12 June 2012 - 11:42 AM

I use the Entity Framework, which is like a newer technology than typical database stuff. Easier if you know LINQ or lambda. That would be the first thing is to figure out what type of database you want then google some tutorials.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1