dataset.writeXml

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christina Androne

    dataset.writeXml

    Hello

    I am using the dataset.WriteXm l method to convert a dataset's content to
    an XML string which will be parsed later on. I initally used WriteXml
    with a stream parameter, then got the string representing the XML from
    it. The problem was that special characters, such as currency symbols,
    are not escaped in the final string. So of course later on trying to XML
    parse that string fails.
    I also used an XmlTextWriter as the WriteXml parameter, then obtained
    the XML string from xmlTextWriter.B aseStream. Special chars are still
    not escaped.

    Can anybody put me on the right track with this?

    Thank you,
    Christina Androne
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: dataset.writeXm l

    What do you mean special characters are not escaped? If you produce the
    XML from the data set, then it should load up fine when you pass that back
    to a data set.

    You mention special characters. Can you show the output of one of your
    calls to write xml? Also, if you are writing to a string, why not use a
    StringWriter, and then get the string to pass around.

    Also, is there an encoding issue here? Is it possible that you have
    data that is not being encoded correctly (unicode chars and ascii encoding
    perhaps)?

    Hope this helps.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Christina Androne" <achristina@hom e.ro> wrote in message
    news:O4CK%23NI4 FHA.3976@TK2MSF TNGP15.phx.gbl. ..[color=blue]
    > Hello
    >
    > I am using the dataset.WriteXm l method to convert a dataset's content to
    > an XML string which will be parsed later on. I initally used WriteXml with
    > a stream parameter, then got the string representing the XML from it. The
    > problem was that special characters, such as currency symbols, are not
    > escaped in the final string. So of course later on trying to XML parse
    > that string fails.
    > I also used an XmlTextWriter as the WriteXml parameter, then obtained the
    > XML string from xmlTextWriter.B aseStream. Special chars are still not
    > escaped.
    >
    > Can anybody put me on the right track with this?
    >
    > Thank you,
    > Christina Androne[/color]


    Comment

    • Christina Androne

      #3
      Re: dataset.writeXm l

      Nicholas Paldino [.NET/C# MVP] wrote:[color=blue]
      > What do you mean special characters are not escaped? If you produce the
      > XML from the data set, then it should load up fine when you pass that back
      > to a data set.[/color]

      It only happends when I am producing XML from a dataset with a currency
      symbol column, which contains items such as £.
      [color=blue]
      >
      > You mention special characters. Can you show the output of one of your
      > calls to write xml? Also, if you are writing to a string, why not use a
      > StringWriter, and then get the string to pass around.[/color]

      (ods is OracleClientDat aset)

      I used to use this:

      System.IO.Strin gWriter sw = new System.IO.Strin gWriter();
      ods.WriteXml(sw , XmlWriteMode.Wr iteSchema);
      string s = sw.ToString();
      sw.Close();
      ods.Clear();


      And then I replaced with this:


      XmlTextWriter xw = new XmlTextWriter(m s, System.Text.Enc oding.Unicode);
      ods.WriteXml(xw , XmlWriteMode.Wr iteSchema);
      StreamReader sr = new StreamReader(xw .BaseStream, true);


      hoping that £ will be output as &#163; or to whatever escaping sequence
      that is correct (as I am not sure if this is the one)

      Basically, from a column such as this:

      SYMBOL
      £


      I need a string such as

      "<ELEMENT>
      <SYMBOL>&#163 ;</SYMBOL>
      </ELEMENT>
      <ELEMENT>
      <SYMBOL>€</SYMBOL>
      </ELEMENT>"

      What I am getting now is:

      "<ELEMENT>
      <SYMBOL>£</SYMBOL>
      </ELEMENT>
      <ELEMENT>
      <SYMBOL>€</SYMBOL>
      </ELEMENT>"

      This last one fails because of the currency symbols (for the skeptics,
      I've removed them to test if XML is valid without them, it is).
      [color=blue]
      >
      > Also, is there an encoding issue here? Is it possible that you have
      > data that is not being encoded correctly (unicode chars and ascii encoding
      > perhaps)?[/color]

      I don't know the answer to that one; except for the second example I am
      not specifying any encoding anywhere (assuming unicode is default). If
      it's not too much to ask, can you point me where I could check for
      having the right encoding?

      Thank you,
      Christina Androne

      Comment

      Working...