Solved

XML parsing and removing

Posted on 2008-10-06
2
350 Views
Last Modified: 2013-12-17
I need to remove some lines from some XML files, specifically some of the xmlns stuff, but I need to do it in batches of thousands of files.

I'm trying to write a program that will ream the folder and remove the xmlsn:addData and xmlns:form from each file that looks like this... I'm not very adept with XML, so I'm having a rough time understanding what each of these elements are. Any ideas?

I'm using C# as my coding language.
<document xmlns="http://www.ademero.com/XmlSchemas/ContentCentral/XmlCaptureDescriptorV1.1" 
		  xmlns:addData="http://www.abbyy.com/FlexiCapture/Schemas/Export/AdditionalFormData.xsd" 
		  xmlns:form="http://www.abbyy.com/FlexiCapture/Schemas/Export/FormData.xsd">
	<imageFiles>
		<file>Images\AIRCO-V9516NT_1.pdf</file>
	</imageFiles>
	<destination>
		<catalog docType="default">Accounts Payable</catalog>
	</destination>
	<fields>
		<field name="Invoice">V9516NT</field>
		<field name="Vendor">AIRCO INC</field>
		<field name="Date">1999-04-14</field>
	</fields>
</document>

Open in new window

0
Comment
Question by:developernetwork
2 Comments
 
LVL 22

Accepted Solution

by:
Ivo Stoykov earned 500 total points
ID: 22650819
Hello developernetwork
Please try the code below
HTH
I

    private void test()
    {
      String s = "<document xmlns=\"http://www.ademero.com/XmlSchemas/ContentCentral/XmlCaptureDescriptorV1.1\" xmlns:addData=\"http://www.abbyy.com/FlexiCapture/Schemas/Export/AdditionalFormData.xsd\" xmlns:form=\"http://www.abbyy.com/FlexiCapture/Schemas/Export/FormData.xsd\"> <imageFiles> <file>Images\\AIRCO-V9516NT_1.pdf</file> </imageFiles> <destination> <catalog docType=\"default\">Accounts Payable</catalog> </destination> <fields> <field name=\"Invoice\">V9516NT</field> <field name=\"Vendor\">AIRCO INC</field> <field name=\"Date\">1999-04-14</field> </fields></document>";
      XmlDocument x = new XmlDocument();
      x.LoadXml(s);
      ((XmlElement)x.DocumentElement).RemoveAttribute("xmlns:addData");
      ((XmlElement)x.DocumentElement).RemoveAttribute("xmlns:form");
      Debug.WriteLine(x.OuterXml);
    }

Open in new window

0
 

Author Comment

by:developernetwork
ID: 22678355
Thanks, that worked! I'm sorry it took me so long to get back to you.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

809 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