【问题标题】:Adding a stylesheet declaration in my xml using Xerces-C使用 Xerces-C 在我的 xml 中添加样式表声明
【发布时间】:2011-01-20 13:24:15
【问题描述】:

我有一个使用 Xerces-C 作为主要 xml 操作库的 c++ 应用程序。

我有我的 DOMDocument* 和我的解析器,我想设置声明。

我执行以下操作:

parser->setValidationScheme(xercesc::XercesDOMParser::Val_Never);
parser->setDoSchema(false);
parser->setLoadExternalDTD(false);

我要补充:

<?xml-stylesheet type="text/xsl" href="my_xslt.xsl"?>

我该怎么做?

【问题讨论】:

    标签: c++ xml stylesheet xerces-c xml-declaration


    【解决方案1】:

    您需要在 DOMDocument 上使用 createProcessingInstruction http://xerces.apache.org/xerces-c/apiDocs-3/classDOMDocument.html#ce898787ba20c00c85be63f28a358507

    创建后,将其附加到 DocumentElement。

    【讨论】:

    • 好吧,我尝试了它并以某种方式工作,但我找到了一个更好的解决方案,在我的上下文中,使用另一个功能......在字符串中写入声明以解析......书面声明也被解析。 ..但是谢谢你:)
    【解决方案2】:

    这是执行此操作的代码:

    xercesc::DomDocument *doc;
    // ... (initialize doc in some way)
    auto root = doc->getDocumentElement();
    auto stylesheet = doc->createProcessingInstruction
      (X("xml-stylesheet"), X("type=\"text/xsl\" href=\"custom.xsl\""));
    doc->insertBefore(stylesheet, root);
    

    这样,样式表信息出现在文档的序言中,这是它的典型位置。 X() 是一些将 C 风格的字符串编码为 Xerces 兼容的 XMLCh-string 的函数。

    【讨论】:

      猜你喜欢
      • 2012-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多