我在c ++中使用Xerces-C作为主要的xml操作库。
我有我的DOMDocument *和我的解析器,我想设置声明。
我执行以下操作:
parser->setValidationScheme(xercesc::XercesDOMParser::Val_Never);
parser->setDoSchema(false);
parser->setLoadExternalDTD(false);
我想补充一下:
<?xml-stylesheet type="text/xsl" href="my_xslt.xsl"?>
我该怎么做?
答案 0 :(得分:1)
您需要在DOMDocument上使用createProcessingInstruction http://xerces.apache.org/xerces-c/apiDocs-3/classDOMDocument.html#ce898787ba20c00c85be63f28a358507
创建后,将其附加到DocumentElement。
答案 1 :(得分:0)
以下是执行此操作的代码:
public ActionResult List_Read([DataSourceRequest] DataSourceRequest request,
Int32 InstitutionId, String CacheKey)
{}
这样,样式表信息出现在文档的序言中,这是它的典型位置。 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);
是一种函数,它将C风格的字符串编码为与Xerces兼容的X()
- 字符串。