HighTechTalks DotNet Forums  

Unexpected character escaping?

Dotnet XML microsoft.public.dotnet.xml


Discuss Unexpected character escaping? in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Jonny Bergdahl
 
Posts: n/a

Default Unexpected character escaping? - 12-13-2007 , 10:20 AM






I have developed an application where the user edits an XML file. I am trying to add som utility functions to the application, where I need to manipulate the XML content programmatically.

---Code snippet--------------
XmlDocument document = new XmlDocument();
document.PreserveWhitespace = true;
document.LoadXml(m_XmlContent);
..... Manipulate content using the DOM ...
m_XmlContent = document.OuterXml;
----------------------------

--XML content snippet------
<Text Condition="string-length(/Node) > 0">Text string</Text>
---------------------------

Problem is that after loading this node gets the Condition attribute changed:
<Text Condition="string-length(/Node) &gt; 0">Text string</Text>


As far as I have researched, the ">" character is a valid XML character in attributes, so I see no reason for why it should be escaped by loading it into an XmlDocument?

How do I resolve this problem?

Regards;
/jb



Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: Unexpected character escaping? - 12-13-2007 , 12:14 PM






Jonny Bergdahl wrote:

Quote:
As far as I have researched, the ">" character is a valid XML character
in attributes, so I see no reason for why it should be escaped by
loading it into an XmlDocument?
The character is not escaped by loading it, rather it is escaped when
the serializer gives you the OuterXml.

Quote:
How do I resolve this problem?
That is difficult, unless you want to implement your own XmlWriter.
Why is the escaping a problem for you? It should not matter whether the
'>' is escaped or not, the attribute value is the same.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
  #3  
Old   
WenYuan Wang [MSFT]
 
Posts: n/a

Default Re: Unexpected character escaping? - 12-17-2007 , 04:16 AM



Hello Jonny,
Thanks for Martin's reply.

">" sign is a valid XML character in attributes, but I'm afraid to say
XMLDocument always escape it to be on the safe side. This behavior is by
design. As Martin said, it's very difficult to workaround it. But this
behavior should not effect on your application. It should not matter
whether the sign is escaped, the value is the same. Do you face any further
issue on this?

If you have any more concern, please feel free to update here again. We are
glad to assist you.
Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
  #4  
Old   
Jonny Bergdahl
 
Posts: n/a

Default Re: Unexpected character escaping? - 12-17-2007 , 08:47 AM



OK, thanks for the clarification. Since it is designed that way, I will have
to live with that.

Regards;
/jb

"WenYuan Wang [MSFT]" <v-wywang (AT) online (DOT) microsoft.com> skrev i meddelandet
news:zXxl71IQIHA.7908 (AT) TK2MSFTNGHUB02 (DOT) phx.gbl...
Quote:
Hello Jonny,
Thanks for Martin's reply.

">" sign is a valid XML character in attributes, but I'm afraid to say
XMLDocument always escape it to be on the safe side. This behavior is by
design. As Martin said, it's very difficult to workaround it. But this
behavior should not effect on your application. It should not matter
whether the sign is escaped, the value is the same. Do you face any
further
issue on this?

If you have any more concern, please feel free to update here again. We
are
glad to assist you.
Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.



Reply With Quote
  #5  
Old   
WenYuan Wang [MSFT]
 
Posts: n/a

Default Re: Unexpected character escaping? - 12-18-2007 , 02:35 AM




Thanks for your understanding.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.