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 131045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:02:37+00:00 2026-05-11T06:02:37+00:00

Ok, I’m reading data from a stream using a StreamReader. The data inside the

  • 0

Ok, I’m reading data from a stream using a StreamReader. The data inside the stream is not xml, it could be anything.

Based on the input StreamReader I’m writing to an output stream using an XmlTextWriter. Basically, when all is said and done, the output stream contains data from the input stream wrapped in a element contained in a parent element.

My problem is twofold. Data gets read from the input stream in chunks, and the StreamReader class returns char[]. If data in the input stream contains a ‘]]>’ it needs to be split across two CDATA elements. First, how do I search for ‘]]>’ in a char array? And second, because I’m reading in chunks, the ‘]]>’ substring could be split across two chunks, so how do I account for this?

I could probably convert the char[] to a string, and do a search replace on it. That would solve my first problem. On each read, I could also check to see if the last character was a ‘]’, so that on the next read, if the first two characters are ‘]>’ I would start a new CDATA section.

This hardly seems efficient because it involves converting the char array to a string, which means spending time to copy the data, and eating up twice the memory. Is there a more efficient way, both speedwise and memory wise?

  • 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. 2026-05-11T06:02:37+00:00Added an answer on May 11, 2026 at 6:02 am

    second, because I’m reading in chunks, the ‘]]>’ substring could be split across two chunks, so how do I account for this?

    Indeed, you would have to keep back the last two characters in a queue instead of spitting them out immediately. Then when new input comes in, append it to the queue and again take all but the last two characters, search-and-replace over them, and output.

    Better: don’t bother with a CDATA section at all. They’re only there for the convenience of hand-authoring. If you’re already doing search-and-replace, there’s no reason you shouldn’t just search-and-replace ‘<’, ‘>’ and ‘&’ with their predefined entities, and include those in a normal Text node. Since those are simple single-character replacements, you don’t need to worry about buffering.

    But: if you’re using an XmlTextWriter as you say, it’s as simple as calling WriteString() on it for each chunk of incoming text.

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

Sidebar

Ask A Question

Stats

  • Questions 209k
  • Answers 210k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, there is a better way to do this: Select… May 12, 2026 at 9:52 pm
  • Editorial Team
    Editorial Team added an answer There is no such thing such as .net standard. ISO/IEC… May 12, 2026 at 9:52 pm
  • Editorial Team
    Editorial Team added an answer You're missing @After method which is why you're seeing this… May 12, 2026 at 9:52 pm

Related Questions

OK, I know what you're thinking, "why write a method you do not want
Ok, I asked a question earlier about Flex and ADO.NET Data Services but didn't
Ok, I have been working with Solaris for a 10+ years, and have never
OK, I know there have already been questions about getting started with TDD ..
Ok, I have a strange exception thrown from my code that's been bothering me

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.