English 中文(简体)
我如何预先安排精简?
原标题:How do I prepend a Stream?

我把Im 装船从数据库中排出,作为星体阵列,我把它放在一个记忆中,以便我能够将其装入用于 par的Xml文件。

然而,有多根 no子的博览会,造成 par子被炸。

我的解决方案是,只拿出一个包含整个博彩的新根 no。

最后,我可以加上一位流作家的罚款,但我可以说明如何在一开始增加。

我怎么能够坐视一流?


Update
I was having too much trouble getting this to work. The "XML" I was extracting was not proper XML and I kept on having to add more and more regexes to remove bad XML before the XmlDocument Load. I ended up using the HtmlAgilityPack to parse out my valid sections of XML and I put those inside their own xml documents. Not the nicest solution but it works. Sigh

最佳回答

由于您已经拥有<代码>逐[]阵列,因此,在阵列之前和之后,在记忆流上,应更方便地撰写:

// bytes from db
byte[] multipleNodes = Encoding.UTF8.GetBytes("<first>..</first><second>..</second><third>..</third>");

using (var ms = new MemoryStream())
{
    // write opening tag
    byte[] newRoot = Encoding.UTF8.GetBytes("<newRoot>");
    ms.Write(newRoot, 0, newRoot.Length);

    ms.Write(multipleNodes, 0, multipleNodes.Length);

    // write opening tag
    byte[] closeNewRoot = Encoding.UTF8.GetBytes("</newRoot>");
    ms.Write(closeNewRoot, 0, closeNewRoot.Length);

    // reset cursor position before pass it to xmldoc
    ms.Position = 0;

    var xml = new XmlDocument();
    xml.Load(ms);

    Console.WriteLine(xml.InnerXml);
}

但是,由于<代码>XmlDocument也提供了<编码>LoadXml(str),我觉得操纵扼杀应当更直接地解决问题:

// bytes from db
byte[] multipleNodes = Encoding.UTF8.GetBytes("<first>..</first><second>..</second><third>..</third>");

string stringFromBlob = Encoding.UTF8.GetString(multipleNodes);
string withRootNode = string.Format("<newRoot>{0}</newRoot>", stringFromBlob);

var xml = new XmlDocument();
xml.LoadXml(withRootNode);

Console.WriteLine(xml.InnerXml);
问题回答

你可以直接 t。 这导致两种选择:

  • write in an opening tag into the memorystream prior to loading the blobs
  • create a second memorystream, write in an opening tag, copy the first into the second...

这是我使用的:

public class CompositeStream : FileStream
{
    Stream[] childStreams;
    int currentStreamIndex = 0;
    Stream currentStream;
    public long totalStreamRead{get; private set;}

    public CompositeStream(string pre, FileStream s_file, string post)
        : base(s_file.SafeFileHandle, FileAccess.Read)
    {
        totalStreamRead = 0;

        MemoryStream s_pre = new MemoryStream();
        MemoryStream s_post = new MemoryStream();

        byte[] b_pre = Encoding.UTF8.GetBytes(pre);
        s_pre.Write(b_pre, 0, b_pre.Length);
        s_pre.Flush();
        s_pre.Seek(0, SeekOrigin.Begin);

        byte[] b_post = Encoding.UTF8.GetBytes(post);
        s_post.Write(b_post, 0, b_post.Length);
        s_post.Flush();
        s_post.Seek(0, SeekOrigin.Begin);

        childStreams = new Stream[] { s_pre, s_file, s_post };

        currentStream = childStreams[currentStreamIndex++];
    }

    public override int Read(byte[] buffer, int offset, int count)
    {
        int totalBytesRead = 0;
        while (count > 0)
        {
            // Read what we can from the current stream
            int numBytesRead = currentStream.Read(buffer, offset, count);
            totalBytesRead += numBytesRead;
            count -= numBytesRead;
            offset += numBytesRead;

            // If we haven t satisfied the read request, 
            // we have exhausted the current stream.
            // Move on to the next stream and loop around to read more data.
            if (count > 0)
            {
                // If we run out of child streams to read from...
                if (currentStreamIndex >= childStreams.Length)
                    break; //get out

                currentStream.Close();
                currentStream = childStreams[currentStreamIndex++];
            }
        }
        totalStreamRead += totalBytesRead;
        return totalBytesRead;
    }
}

这样做的一个清洁办法是执行<条码>CompositeStreamReader,接受若干流,然后按顺序宣读。

https://web.archive.org/web/20100721082808/http://blogs.msdn.com/b/paolos/archive/04/08/how-to-boost-message-transformations-using-the-xslcompiledtransform-stat-ext.aspx” rel=“nofollow noreferer” https://web.archive.org/web/20100721082808/http://blogs.msdn.com/b/paolos/archive/0408/how-to-boost-message-transformations-using-the-xslcompiledtransform-class-extil.aspx 你们可以适应,但你可以放弃更简单的东西。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签