简体   繁体   中英

Unicode escape characters not being read by XmlReader

I've got an XML document that I'm importing into an XmlReader that has some unicode formatting I need to preserve. I'm preserving the whitespace but it's dropping the encoded #x2028 which I assume should be expressed as a line break.

Here's my code:

var settings = new XmlReaderSettings
                   {
                       ProhibitDtd = false,
                       XmlResolver = null,
                       IgnoreWhitespace = false
                   };

var reader = XmlReader.Create(new StreamReader(fu.PostedFile.InputStream), settings);
var document = new XmlDocument {PreserveWhitespace = true};
document.Load(reader);
return document;

XML example:

<td valign="top" align="center">Camels and camel &#x2028;resting place</td>

How do I get to those characters to I can render br tags?

Your question is unclear: do you expect the XmlReader to translate the &#x2028; into an HTML <br> tag? That isn't going to happen.

Or are you examining the actual character content of the <td> element (within the code, not as printed/displayed) and seeing "camel resting place"? If yes, please show the code that you're using to verify this, because it would be a pretty major bug.

Or something else?

将代码导入阅读器后,我可以找到并替换该字符:

Regex.Replace(s, "\u2028", "<br/>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM