简体   繁体   English

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

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

I have a data source from which my program creates a well-formed XML-file which should be used later in a xsl-file. 我有一个数据源,程序会从该数据源创建格式正确的XML文件,以后应在xsl文件中使用该文件。

The data-source contains latex special chars. 数据源包含乳胶特殊字符。 I'm mapping them and creating local Entites. 我正在映射它们并创建本地实体。

An example. 一个例子。

xml data: 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>

The line <publisher>Birkh&amp;e228;user, Boston - Basel - Berlin</publisher> should be <publisher>Birkh&e228;user, Boston - Basel - Berlin</publisher> . <publisher>Birkh&amp;e228;user, Boston - Basel - Berlin</publisher>应该是<publisher>Birkh&e228;user, Boston - Basel - Berlin</publisher> So the program converts the & into &amp; 因此,程序会将&转换为&amp; .

Im writing in C# and using the XmlDocument to write the xml-file. 我用C#编写并使用XmlDocument编写xml文件。

How can I prevent the program to convert the & into an &amp; 如何防止程序将&转换为&amp; ?

Kind Regards Mario 亲切的问候马里奥

Edit: I tried much with converting the &amp; 编辑:我做了很多转换&amp;尝试&amp; within the xsl, but nothing worked well. 在xsl中,但没有任何效果。

First I inserted the entities directly with their decimal code, than I tried it with the local own ones. 首先,我直接使用实体的十进制代码插入实体,然后尝试使用本地自己的十进制代码插入实体。 The result was the same. 结果是一样的。 I got &amp;code; 我得到了&amp;code; than &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