XML Serialization

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

    #1

    XML Serialization

    I have a class which I am using XML Serialization with, something like:

    public class MyObj
    {
    [XmlAttributeAtt ribute(DataType ="string", AttributeName=" Text")]
    public string text;

    [XmlAttributeAtt ribute(DataType ="boolean", AttributeName=" Allow")]
    public bool allow;
    }

    All works fine until I have a string that contains a backslash in the text
    member. For some reason, in this case, the XML Serializaer doesn't output
    this member. Can anyone tell me what I need to do to get this to work please?

    What I want to do is to be able to specify regular expressions in the program
    and save them to a user file.



    Many thanks in advance.
  • dickster

    #2
    Re: XML Serialization

    I cannot regenerate this error - Got this to work

    <?xml version="1.0" encoding="ibm85 0"?>
    <MyObj xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" Text="Dick\ster "
    Allow="true" />


    Dickster

    Comment

    • lazygenius

      #3
      Re: XML Serialization

      Thanks for the reply Dickster. The only difference i've got is that the
      encoding is "utf-8" in my XML file- maybe that's something to do with it?

      Comment

      • dickster

        #4
        Re: XML Serialization

        I had been serialising to the Console - which I didn't seem to be able
        to set to UTF-8

        however when I serialise to a file

        ------------------------------------------------------------------
        Dim tw As New System.Xml.XmlT extWriter( _
        New System.IO.FileS tream("C:\Dicks ter.xml", System.IO.FileM ode.Create),
        _
        New System.Text.UTF 8Encoding(True) )

        XmlSerializerOb j.Serialize(tw, Obj)
        ------------------------------------------------------------------

        I get the following in the output file C:\Dickster.xml
        ------------------------------------------------------------------
        <?xml version="1.0" encoding="utf-8"?><MyObj
        xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" Text="Dick\ster "
        allow="true" />
        ------------------------------------------------------------------

        Dickster

        (PS: I use VB.NET but this should have no relevance to the problem)

        Comment

        Working...