Replace stringxs in XML with RegEx

Richard Kreidl
Richard Kreidl used Ask the Experts™
on
How would I replace the certains nodes in a XML with blanks??

Current XML file
<?xml version="1.0" encoding="utf-8"?>
<IndividualListing>
  <Individual>
    <Item_ID>1</Item_ID>
    <Name>Abraham, Tom</Name>
    <Pager>7010947@archwireless.net </Pager>
  </Individual>
  <Individual>
    <Item_ID>2</Item_ID>
    <Name>Acosta, John</Name>
    <Pager>6222075@archwireless.net</Pager>
  </Individual>
  <Individual>
    <Item_ID>3</Item_ID>
    <Name>Ailani, Tom</Name>
    <Pager>5010073@archwireless.net</Pager>
  </Individual>
  <Individual>
    <Item_ID>5</Item_ID>
    <Name>Amistapur Sue</Name>
    <Pager>7225858@archwireless.net</Pager>
  </Individual>
</IndividualListing>

Desired XML file
<?xml version="1.0" encoding="utf-8"?>
<IndividualListing>
  <Individual>
    <Name>Abraham, Tom</Name>
    <Pager>7010947@archwireless.net </Pager>
  </Individual>
  <Individual>
    <Name>Acosta, John</Name>
    <Pager>6222075@archwireless.net</Pager>
  </Individual>
  <Individual>
   <Name>Ailani, Tom</Name>
    <Pager>5010073@archwireless.net</Pager>
  </Individual>
  <Individual>
   <Name>Amistapur Sue</Name>
    <Pager>7225858@archwireless.net</Pager>
  </Individual>
</IndividualListing>

So, bascially I need to remove the <Item_ID> nodes


thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I always like to harness the power of datasets when  i can. I would load it into a dataset and drop the column of the data table

        Dim ds As DataSet = New DataSet()
        ds.ReadXml("XMLFile.xml")
        ds.Tables(0).Columns.Remove("Item_ID")
        ds.WriteXml("XMLNoItems.xml")

Commented:
if you have the XML as a string, you can load it into the dataset by

        Dim xmlData As String = "<?xml version='1.0' encoding='utf-8'?>" + _
                "<IndividualListing><Individual><Item_ID>1</Item_ID><Name>Abraham, Tom</Name>" + _
                "<Pager>7010947@archwireless.net </Pager></Individual><Individual><Item_ID>2</Item_ID><Name>Acosta, John</Name>" + _
                "<Pager>6222075@archwireless.net</Pager></Individual><Individual><Item_ID>3</Item_ID><Name>Ailani, Tom</Name>" + _
                "<Pager>5010073@archwireless.net</Pager></Individual><Individual><Item_ID>5</Item_ID><Name>Amistapur Sue</Name>" + _
                "<Pager>7225858@archwireless.net</Pager></Individual></IndividualListing>"

        Dim xmlSR As System.IO.StringReader = New System.IO.StringReader(xmlData)

        Dim ds As DataSet = New DataSet()
        ds.ReadXml(xmlSR)
Richard KreidlSoftware Developer

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial