2

I have an application in c++ using Xerces-C as main xml manipulation library.

I have my DOMDocument* and my parser and I want to set declarations.

I do the following:

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

I want to add:

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

How can I do it?

Andry
  • 16,172
  • 27
  • 138
  • 246

2 Answers2

1

You'll need to use the createProcessingInstruction on the DOMDocument http://xerces.apache.org/xerces-c/apiDocs-3/classDOMDocument.html#ce898787ba20c00c85be63f28a358507

Once you've created it, append it to the DocumentElement.

James Walford
  • 2,953
  • 1
  • 24
  • 37
  • Well I tried it and somehow worked but I found a better solution, in my context, using another fuctionality... writing the declaration in the string to parse... the written declaration is parsed too... however thank you :) – Andry Jan 20 '11 at 23:45
0

Here is the code for doing this:

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);

This way, the stylesheet information appears in the prolog of the document, which is the typical place for it. X() is some function that encodes a C-style string as a Xerces-compatible XMLCh-string.

piripiri
  • 1,925
  • 2
  • 18
  • 35