Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

XmlReader.ReadString and not resolving entities

Options
  • 26-07-2012 12:27am
    #1
    Moderators, Technology & Internet Moderators, Regional North East Moderators Posts: 10,869 Mod ✭✭✭✭


    Hope this is the right place for this.

    In a nutshell, I'm trying to read an XML file in VB using XmlReader.ReadString method. Tool is working fine, except that the ReadString method is resolving/converting entities, which I do not want it to do.

    So if I have a string in the XML like:
    PauloMN>Boards

    it's being read in as:
    PauloMN>Boards

    Have looked and looked, and can't see a way to specify that entities should not be resolved i.e. I want the original string exactly as contained in the XML file.

    There has to be a flag somewhere I can just set to avoid this behaviour. Any ideas anyone? Thanks!


Comments

  • Registered Users Posts: 527 ✭✭✭Sean^DCT4


    Can't say for sure without seeing the code and xml file. It could be because the value is an XML escape character.

    Have you tried something like:
    Dim mVal As String = SecurityElement.Escape(xmlReader.Value)
    
    MSDN: http://msdn.microsoft.com/en-us/library/system.security.securityelement.escape.aspx

    Or you could try setting the encoding of the stream reader:
    Using rdr As XmlReader = XmlReader.Create(New StreamReader(fileName, Encoding.GetEncoding("ISO-8859-9")))
    	While r.Read()
    		Console.WriteLine(rdr.Value)
    	End While
    End Using
    


  • Registered Users Posts: 11,979 ✭✭✭✭Giblet


    Maybe CDATA will help you here


  • Registered Users Posts: 1,712 ✭✭✭neil_hosey


    if you cant find a solution, an easy workaround would be to encode the data before using it, as thats it is doing, its decoding it..

    the xmlreader is decoding it, you dont want that, so just re-encode it.

    dim a as string = Encoder.HtmlEncode(text)


Advertisement