You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by ul...@gmx.de on 2002/07/02 08:54:36 UTC
Inserting stylesheet instruction etc. + pretty printing
Hi all!
I'm trying to insert a XML declaration and a stylesheet instruction
to a DOM document (using xerces-c1_7_0-win32 and MSVC++ 6.).
(Q1) Is something like this:
DOM_Element rootElem = doc.getDocumentElement();
DOM_Node xslPI =
doc.createProcessingInstruction("xml-stylesheet", "type='text/xsl' href='Proj.xsl'");
DOM_Node xmlDecl = doc.createXMLDecl("1.0", "utf-8", "no");
doc.insertBefore(xmlDecl, rootElem);
doc.insertBefore(xslPI, rootElem);
the "recommended" way to do that?
(Q2) If I do it that way and afterwards write the doc to disk (using
DOMSerializer from Evert Haasdijk) I get a "\x0d\x0d\x0a" after the XML
decl,
but no kind of newline after the XSL instruction. To "fix" this, I added the
following two lines to the above example:
DOM_Node newLine = doc.createTextNode("\n");
doc.insertBefore(newLine, rootElem);
Unfortunately the result is an unhandled exception. Nevertheless I get a XML
file with the correct contents *and* the line break that I wanted to have.
Is there a better (read: no exception) way to achieve that goal?
Thanks for reading (and answering, of course ;-)),
Uli.
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Inserting stylesheet instruction etc. + pretty printing
Posted by ul...@gmx.de.
> > Hi all!
> > I'm trying to insert a XML declaration and a stylesheet instruction
> > to a DOM document (using xerces-c1_7_0-win32 and MSVC++ 6.).
> >
> > (Q1) Is something like this:
> > DOM_Element rootElem = doc.getDocumentElement();
> > DOM_Node xslPI =
> > doc.createProcessingInstruction("xml-stylesheet", "type='text/xsl'
> > href='Proj.xsl'");
> > DOM_Node xmlDecl = doc.createXMLDecl("1.0", "utf-8", "no");
> >
> > doc.insertBefore(xmlDecl, rootElem);
> > doc.insertBefore(xslPI, rootElem);
> > the "recommended" way to do that?
> >
> > (Q2) If I do it that way and afterwards write the doc to disk (using
> > DOMSerializer from Evert Haasdijk) I get a "\x0d\x0d\x0a" after the XML
> > decl,
> > but no kind of newline after the XSL instruction. To "fix" this, I added
> > the
> > following two lines to the above example:
> > DOM_Node newLine = doc.createTextNode("\n");
> > doc.insertBefore(newLine, rootElem);
> > Unfortunately the result is an unhandled exception. Nevertheless I get a
> > XML
> > file with the correct contents *and* the line break that I wanted to
> have.
> > Is there a better (read: no exception) way to achieve that goal?
>
> I just found out that the exception is a DOM_DOMException with code
> HIERARCHY_REQUEST_ERR. (As I could have read in the help for
> "insertBefore" -- sorry.)
My (momentary) solution is:
- remove the doc.createTextNode("\n") stuff from my example
- insert a chLF in DOMSerializer::gEndPI
- remove the chCR from DOMSerializer::gXMLDecl4 (BTW there isn't a chCR in
the original DOMPrint.cpp.)
Sorry for bothering you with that trivialities (looking at it afterwards),
Uli.
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Inserting stylesheet instruction etc. + pretty printing
Posted by ul...@gmx.de.
> Hi all!
> I'm trying to insert a XML declaration and a stylesheet instruction
> to a DOM document (using xerces-c1_7_0-win32 and MSVC++ 6.).
>
> (Q1) Is something like this:
> DOM_Element rootElem = doc.getDocumentElement();
> DOM_Node xslPI =
> doc.createProcessingInstruction("xml-stylesheet", "type='text/xsl'
> href='Proj.xsl'");
> DOM_Node xmlDecl = doc.createXMLDecl("1.0", "utf-8", "no");
>
> doc.insertBefore(xmlDecl, rootElem);
> doc.insertBefore(xslPI, rootElem);
> the "recommended" way to do that?
>
> (Q2) If I do it that way and afterwards write the doc to disk (using
> DOMSerializer from Evert Haasdijk) I get a "\x0d\x0d\x0a" after the XML
> decl,
> but no kind of newline after the XSL instruction. To "fix" this, I added
> the
> following two lines to the above example:
> DOM_Node newLine = doc.createTextNode("\n");
> doc.insertBefore(newLine, rootElem);
> Unfortunately the result is an unhandled exception. Nevertheless I get a
> XML
> file with the correct contents *and* the line break that I wanted to have.
> Is there a better (read: no exception) way to achieve that goal?
I just found out that the exception is a DOM_DOMException with code
HIERARCHY_REQUEST_ERR. (As I could have read in the help for
"insertBefore" -- sorry.)
Uli.
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org