Reputation: 1178
I have an XML file with some lines like the following:
<rule pat="&&&&&&&&&&&&&&&(?<B>B) ?(?<AND>&) ?(?<E>E)">
I use TinyXML lib in C++ to parse this XML file, but when I try to get the 'pat' attribute of such lines, the TinyXML turns out just ignore any occurrence of character &
. That is, the result read by TinyXML turns to be like:
(?<B>B) ?(?<AND>) ?(?<E>E)
with all &
missing!
This char is a part of my regular expression pattern, so this will lead to further error in my program.
Do anyone have any idea why this character &
is so SPECIAL and TinyXML just cannot read? even a stand alone &
will be dismissed?
Upvotes: 0
Views: 688
Reputation: 21948
That's not well formed XML. If you want an &
character, you need to put &
.
Upvotes: 2
Reputation: 474476
That's because that is not a valid XML file. You can't just stick an &
character anywhere in XML. You have to escape it with entities:
&
TinyXML will only read valid XML files (or at least mostly valid ones).
Similarly, you need to escape the <
and >
characters too, with <
and >
.
Upvotes: 7