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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

XmlReader.ReadString and not resolving entities

  • 25-07-2012 11:27pm
    #1
    Moderators, Technology & Internet Moderators, Regional North East Moderators Posts: 10,878 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, Registered Users 2 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, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    Maybe CDATA will help you here


  • Registered Users, Registered Users 2 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