Menu

Removing Auto AddSlashes?

Anonymous
2004-07-03
2004-07-03
  • Anonymous

    Anonymous - 2004-07-03

    Hey,

    I don't know if this is just standard file I/O stuff or if TinyXML does it on purpose or what, but I have a tag taht says something like:

    <Tag>A line of text\r\nAnother line\r\n</Tag>

    The problem is when I read this into my program using TinyXML then display it, it actually shows the \r\n instead of doing the newline like it has been "addslashed()" if you were using php.

    So, I was wondering if there was a way fo "turning this off" or if I'm going to have to parse it out?

    Thanks
    - kahsm

     
    • B Sizer

      B Sizer - 2004-07-03

      This isn't TinyXML changing your text, but rather a slight misunderstanding of how text handling works.

      The "\r\n" is not inherently a newline sequence; it just happens to be the way that some languages (eg. C, Java, PHP) represent it. When they compile a string containing those sequences, they change them internally to the non-printing characters that the sequence represents. (ie. A 13 and a 10, I believe.)

      In XML, what you have there is a backslash, an 'r', another backslash, and an 'n'; no more, no less. TinyXML processes this as-is and hands you back exactly what you gave it. So what you might choose to do is conduct a search and replace in the nodes yourself to swap these sequences for the actual values you want. It really depends on how you want to represent the data in the end.

       
    • Anonymous

      Anonymous - 2004-07-03

      I understand how it works. And I also understand that many people wouldn't want special characters recognized when they import strings and that's why xml does whatever it does to stop it.

      What I was asking I guess was if I can't do that, and I can't just use hard returns, how would I represent a new line in an xml file.

      And by your response it seems you're saying you can't, use something ambiguous like {newline} and parse it out.

      Thanks =)
      - Kahsm

       
      • B Sizer

        B Sizer - 2004-07-03

        It's not that XML 'stops' special characters, it just doesn't interpret those particular characters the way that you want it to. Those characters are only special in a certain context and XML isn't that context. You could use &#0A; and &#0D; to represent \n and \r but I've no idea what TinyXML does with those.

         
    • Ellers

      Ellers - 2004-07-03

      "how would I represent a new line in an xml file"

      err.. don't you mean by pressing 'enter' in your text, like this:

      <Tag>A line of text
      Another line
      </Tag>

      If you use a text editor (a tiny free one that I can recommend is MetaPad) you can choose whether the line endings are DOS (0x0D0x0A) or Unix (0x0A only I think).

      I hope I'm not misunderstanding you...

      Alternatively, if you use a C-string and read the xml from memory, then your \r \n escape sequences will work just fine, but from a file you're reading the actual "\" chars.

      HTH

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.