繁体   English   中英

保存XML文件而无需将&转换为&

[英]Saving XML-File without converting & into & amp;

我有一个数据源,程序会从该数据源创建格式正确的XML文件,以后应在xsl文件中使用该文件。

数据源包含乳胶特殊字符。 我正在映射它们并创建本地实体。

一个例子。

xml数据:

<!DOCTYPE my_entities[...<!ENTITY e228 "&#228;">]...>
  <inproceedings id="Abadie:94">
    <author>B. Abadie</author>
    <title>{''Vector bundles'' over quantum Heisenberg manifolds}</title>
    <booktitle>Algebraic Methods in Operator Theory</booktitle>
    <editor>R. Curto and P. E. T. J&amp;e248;rgensen</editor>
    <publisher>Birkh&amp;e228;user, Boston - Basel - Berlin</publisher>
    <year>1994</year>
  </inproceedings>

<publisher>Birkh&amp;e228;user, Boston - Basel - Berlin</publisher>应该是<publisher>Birkh&e228;user, Boston - Basel - Berlin</publisher> 因此,程序会将&转换为&amp;

我用C#编写并使用XmlDocument编写xml文件。

如何防止程序将&转换为&amp;

亲切的问候马里奥

编辑:我做了很多转换&amp;尝试&amp; 在xsl中,但没有任何效果。

首先,我直接使用实体的十进制代码插入实体,然后尝试使用本地自己的十进制代码插入实体。 结果是一样的。 我得到了&amp;code; &code;

static void Create_Filled_XML() {
    XmlDocument doc = new XmlDocument();
    doc.XmlResolver = null;

    try {
        string docType = "";
        foreach(KeyValuePair<string, DocEntity> pair in CommandMapper.SymbolMap)
                docType += pair.Value.GetEntityString();

        XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
        XmlDocumentType myDocType = doc.CreateDocumentType("my_entities", null, null, docType);
        XmlProcessingInstruction xslStyle = doc.CreateProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"03_bibtex.xsl\"");

        XmlNode root = doc.CreateElement("bibtext");

        foreach(BibElement bib in bibtex) {
            root.AppendChild(bib.GetXml(doc));
        }

        doc.AppendChild(dec);
        doc.AppendChild(myDocType);
        doc.AppendChild(xslStyle);
        doc.AppendChild(root);

        doc.Save(@"...\file.xml");
    } catch(Exception ex) {
        Console.WriteLine();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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