Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:49:22+00:00 2026-06-09T18:49:22+00:00

I’m required to write a tool that can handle the below XML fragment that

  • 0

I’m required to write a tool that can handle the below XML fragment that is not well formed as it contains XML declarations in the middle of the stream.

The company already has these kinds files in use for a long time, so there is no option to change the format.

There is no source code available that does the parsing, and the platform of choice for new tooling is .NET 4 or newer preferably with C#.

This is how the fragments look like:

<Header>
  <Version>1</Version>
</Header>
<Entry><?xml version="1.0"?><Detail>...snip...</Detail></Entry>
<Entry><?xml version="1.0"?><Detail>...snip...</Detail></Entry>
<Entry><?xml version="1.0"?><Detail>...snip...</Detail></Entry>
<Entry><?xml version="1.0"?><Detail>...snip...</Detail></Entry>

Using an XmlReader with the XmlReaderSettings.ConformanceLevel set to ConformanceLevel.Fragment, I can read the complete <Header> element fine.
Even the <Entry> element start is OK, however while reading the <Detail> info the XmlReader it throws an XmlException, as it reads in the <?xml...?> XML declaration which it doesn’t expect at that place.

What options do I have to skip over those XML declarations, besides heavy string manipulations?

Since the fragments can easily go above 100 megabyte a piece, I’d rather do not load everything into memory at once. But it that is what it takes, I am open for it.

Example of the exceptions I get:

System.Xml.XmlException: Unexpected XML declaration.
The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it.
Line ##, position ##.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:49:24+00:00Added an answer on June 9, 2026 at 6:49 pm

    I don’t think the built in classes will help; you’ll probably have to do some preparsing and remove the extra headers. If your sample is accurate, you can just do a string.Replace(badXml, "<?xml version=\"1.0\"?>, "") and be on your way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am required to write a script that would download a file (based on
I'm required to write a JCE provider. I have learned that I need to
write a script that takes two optional boolean arguments,--verbose‚ and ‚--live, and two required
Can anyone give me an example of successful non-programmer, 5GL (not that I am
I'm looking for a simple tool, preferably one that I can redistribute with my
I'm trying to write up a tool that requires knowledge of the state of
I'd like to write a small build helper tool that shall read some properties
I'm required to write documentation for my current project that lists all .c files
I am required to write a C++ application to run on an embedded Linux
Does anyone know what is required to be able to read and write to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.