Solved

XML parsing and removing

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linq Help 1 35
Not showing page correctly 3 29
ASP.NET 5 Templates 2 65
Show/Hide ASP.NET controls with JQuery best practices 3 10
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…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now