1

I need to parse a XML document in which there are conditions like the below example:

<element condition="var < 5">element name</element>

The problem is that the parser doesn't allow this 'is less than' (<) character.

I tried GDataXML -> it gives me an error saying there is an illegal character.

I also tried TBXML -> it doesn't take into account the attributes where there is this character.

I guess it's the same for other parsers.

How can I fix this?

Nealbo
  • 529
  • 4
  • 20
Hooli
  • 33
  • 7

1 Answers1

5

You should replace < with &lt;

WojtekT
  • 4,735
  • 25
  • 37
  • Thx for you answer. The problem is that this XML document could be edited by non-IT people. I'd like not to ask them to type < – Hooli May 21 '12 at 10:13
  • How can i do that ? Take the XML document as a big string and use a replace string method to replace < with < ? But it will replace the character from the tags too. – Hooli May 21 '12 at 10:17
  • There's no simple solution. Problem is that `<` is an incorrect character as far as xml goes. – WojtekT May 21 '12 at 10:18
  • 6
    If they're not technical, they shouldn't edit the xml. You can provide a form that escapes those characters. – user845279 May 21 '12 at 10:21
  • @user845279 is absolutely right; if a user is isn't technical enough to know the formatting rules for XML, then he shouldn't be editing it. XML doesn't have that many rules, but the rules it does have it is *very* strict about; any error in the code will cause any XML software to reject the whole file. – Spudley May 21 '12 at 19:50