Solved

XML parsing and removing

Posted on 2008-10-06
2
352 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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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