Solved

XML parsing and removing

Posted on 2008-10-06
2
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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