how to get some text into a XMLWriter?

This should be sooo easy.

I've got a XMLWriter object

I've got a XMLNode

How do I get the XMLNode.OuterText into the XMLWriteObject without having to go through hoops messing about with streams, textwriters or any other derived stupidity or otherwise writing lines and lines and lines of code when I should be able to do this in about 3 lines

These new readers and writers are rubbish. They just bend my head backwards every time I have to use them. Either I'm very very stupid, or they are just long-winded and illogical

And please microsoft, tell w3c they can have thier own xml dom, just ignore them and write us one that isn't sooooooooooooooooooooooooooo obscure, and is missing some very basic functionality

Honstly, all I want is some pretty xml for a customer so he can read documents in a text editor without first using xml notepad to format it, and I've been stotting my head off a brick wall for half a day so far. It's the same every time i have use xml.

*rant mode off*


Answer this question

how to get some text into a XMLWriter?

  • Kogivan

  • sharad sharma

    YeeeeeeeeeeeeeeeeeeeeeesS!

    Sergey (have I said this before ) you are a genius :-). I was so close too, I was trying every method I could to write to the XMLWriter, and I just needed that Node.WriteTo(xmlWriter)

    WooHoo!

    I'll post some code here so you can all share once it's tidied up

  • Qanuc

    it's working now, except the xml text I get out is the same as I put in, i.e. one long un-readable splurge. One of the considerations for XML is that it is machine and human-readable.

    So where is the method in XMLDocument to ouput human-readable XML

    eh eh

  • Asher David

    Calm down.

    XmlReader and XmlWriter are far from be ideal but not as illogical as you see them now.

    When you call xStartNode.OuterXml you already serialize your xStartNode to string.

    xtW.WriteRaw() send it to MemoryStram without any processing. (That's why it is "Raw".)

    Most likely you need:

    Wsettings.Indent=true;
    Dim xtW As XmlWriter = XmlWriter.Create(ms, Wsettings)
    xStartNode.WriteTo(xtW);

    The output will be indented is your document has WS preserved or if you create XmlWriter that performs indentation.



  • Quammy

    and the answer is...

    Dim ms As New MemoryStream
    Dim xtW As XmlWriter = XmlWriter.Create(ms, Wsettings)
    xtW.WriteRaw(xStartNode.OuterXml)
    xtW.Flush()

    There, not obscure at all is it I end up with a nice fat memory stream, full of lovely text that I can't see unless I create another object, a reader, however, it's not working

    Who thought this up


  • how to get some text into a XMLWriter?