English 中文(简体)
如何防止XElement被贬损实体参考
原标题:How to prevent XElement from decoding character entity references

我有一部包含外向的XML插座。 我用等同的“灯塔”取代“黄色”;将经修改的胎体划入“XElement”。 然而,“XElement”正转而成为“apos”。

我如何迫使XElement。 • 保留编码拼法?

string originalXML = @"<Description><data>Mark s Data</data></Description>"; //for illustration purposes only
string encodedApostrophe = originalXML.Replace(" ", "&#39;");
XElement xe = XElement.Parse(encodedApostrophe);
最佳回答

这是正确的行为。 在<代码>允许的地方,该编码与<代码>&';,&#39;&#x27;。 如果你想在XML中列入字面座标注&#39;,请在&:

originalXML.Replace(" ", "&amp;#39;")

或者将原XML加以规范并修改:

XElement xe = XElement.Parse(originalXML);

var data = xe.Element("data");

data.Value = data.Value.Replace(" ", "&#39;");

但是,这样做似乎确实是令人不快的。 或许可以更好地解决你重新努力解决的问题。

此外,这种编码并非“ASCII当量”,而是称作character entities reference/a>。 这些数字是根据统法协会的特性代码点计算的。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签