Headline

Pull-based XML parsing in C# with XmlReader

Motivation

XML processing with XmlReader which provides a lower-level abstraction over the XML file structure. This implementation retains more complexity than other solutions (e.g. Contribution:csharpLinqToXml) but benefits performance.

Illustration

For totaling salaries we read XML file and check for "Salary" nodes. For cutting, we go through the source XML file in a streaming fashion (by using Read() method of XmlReader which reads a current line of an input XML stream and goes to the next one) and write the content as-is into an output string. We maintain a valid XML structure, even temporary it is represented as a string type.

Every time we reach the "Salary" node, we read the content (which is the actual salary) as a decimal number, cut it, and write into an output string.

When the end of the source file is reached, we use XmlTextWriter to produce a new XML file from the raw XML content in a string variable.

Architecture

Features.cs contains static methods where Feature:Cut and Feature:Total are implemented. FeaturesTest.cs contains the relates unit tests.

Usage

Technology:Visual Studio 2010 should be used to open a project file. The project itself is a class-library and compiles into a DLL. To run a project you must execute at least one unit test (or all at once). Nunit GUI or other Visual studio extension (e.g. Resharper) should be used for executing unit tests.

Metadata


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    User edits

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.

    10 most similar pages:

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.