Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未从页面中省略xml声明_Xml_Xslt_Asp.net - Fatal编程技术网

未从页面中省略xml声明

未从页面中省略xml声明,xml,xslt,asp.net,Xml,Xslt,Asp.net,我使用XSLT转换来处理XML文件,并将其插入到我的aspx页面的主体中 有关背景信息,请参考以下内容: 我的xml文件中包含以下内容: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" excl

我使用XSLT转换来处理XML文件,并将其插入到我的aspx页面的主体中

有关背景信息,请参考以下内容:

我的xml文件中包含以下内容:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    xmlns:myCustomStrings="urn:customStrings">
  <xsl:output
    method="xml" version="2.0"
    media-type="text/html"
    omit-xml-declaration="yes"
    indent="yes"
 />...unrelated stuff left out here

事实证明,这是我进行转换的方法服务器端的结果

XSLT说什么无关紧要,因为.net方法覆盖了它

我的c代码中出现了以下代码片段:


事实证明,这是我进行转换的方法服务器端的结果

XSLT说什么无关紧要,因为.net方法覆盖了它

我的c代码中出现了以下代码片段:


执行转换的代码将非常有用(例如,如果您最终将输出加载到XmlDocument中并对其执行OuterXml,则不管您的omit xml声明说了什么),添加了转换代码我认为仍然需要更多的上下文。我对测试代码(使用您的代码作为基础)不使用XML声明没有问题。当使用StringWriter时,它使用UTF-16编码,因此如果转换/编写器应用XML声明,它将在编码属性中显示UTF-16(正如我为“省略XML声明”指定“否”时所做的那样)。在你的代码中的某个地方,我认为有更多的上下文是必要的(你认为无关的东西可能不是这样)。在<代码> XML:输出< /代码>中,不应该<代码>版本=“2”<代码>是代码>版本=“1”< /代码>吗?方法是
xml
,但没有xml 2.0。执行转换的代码将非常有用。(例如,如果您最终将输出加载到一个XmlDocument中并在其上执行OuterXml,则不管您的omit xml声明说什么)添加了转换代码我认为还需要更多的上下文。我对测试代码(使用您的代码作为基础)不使用XML声明没有问题。当使用StringWriter时,它使用UTF-16编码,因此如果转换/编写器应用XML声明,它将在编码属性中显示UTF-16(正如我为“省略XML声明”指定“否”时所做的那样)。在你的代码中的某个地方,我认为有更多的上下文是必要的(你认为无关的东西可能不是这样)。在<代码> XML:输出< /代码>中,不应该<代码>版本=“2”<代码>是代码>版本=“1”< /代码>吗?方法是
xml
,但没有xml2.0。
<div id="example" />
    <?xml version="1.0" encoding="utf-8"?><div xmlns:myCustomStrings="urn:customStrings"><div id="imFormBody" class="imFormBody">
public static string SmartNotePageFromTemplate(string patientVisitId, string followupType, bool copyPreviousNote)
    {
        // create custom object
        CustomStrings customStrings = new CustomStrings();//specify class for use in XSLT

        string noteXmlFile = ImSmartNotesConfig.GetSmartNotesXmlFile();//get xml data file name from config
        string noteXslFile = ImSmartNotesConfig.GetSmartNotesXsltFile();// get xslt file name from config

        string subXmlFile = "../SmartNotesXml/testData.xml";
        string subCSSFile = "../CSS/testCSS.css";
        string subJSFile = "../Js/testJS.js";

        try
        {
            XsltSettings settings = new XsltSettings(true, true);// allow the document() in the xslt

            XsltArgumentList xslArg = new XsltArgumentList();// create argument list for xslt
            xslArg.AddParam("subXmlFile", "", subXmlFile);
            xslArg.AddParam("subCSSFile", "", subCSSFile);
            xslArg.AddParam("subJSFile", "", subJSFile);
            //pass an instance of the custom object
            xslArg.AddExtensionObject("urn:customStrings", customStrings);

            XslCompiledTransform myXslt = new XslCompiledTransform(true);// we will use the compiled xslt processor
            myXslt.Load(noteXslFile, settings, new XmlUrlResolver());// load the xslt in
            StringWriter stWrite = new StringWriter();// create output writer

            //myXslt.Transform(noteXmlFile, xslArg, stWrite);// transform 
            SmartNote.BL.SmartNoteLogic logic = new SmartNote.BL.SmartNoteLogic();
            XmlDocument noteXml = logic.GetNewNoteXml(patientVisitId, followupType, copyPreviousNote);
            myXslt.Transform(noteXml, xslArg, stWrite);// transform 

            return stWrite.ToString();// put the StringWriter as a string to the output- html page in this instance, as used in the .aspx.cs file
        }
        catch (Exception e)
        {
            throw e;
        }
    }
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;