You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by fatboyjim <fa...@hotmail.com> on 2006/09/13 18:50:59 UTC

Print XML from DOM tree

Hi all,

I am able to write XML to a string using a DOMWriter and the writeToString()
method.

This works fine. I am wondering, is there a way to get 'prettier' output?
ie. a new line after each element, and an extra indent between child
elements, like XML is displayed in Internet Explorer etc

Thanks for your time

Jim
-- 
View this message in context: http://www.nabble.com/Print-XML-from-DOM-tree-tf2266523.html#a6289687
Sent from the Xerces - C - Users forum at Nabble.com.


Re: Re : Print XML from DOM tree

Posted by fatboyjim <fa...@hotmail.com>.
Alberto,

Sorry I didn't reply earlier, I haven't had access to the internet

The code I am using is as follows:


	static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
	DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(gLS);
	DOMWriter* writer = ((DOMImplementationLS*)impl)->createDOMWriter();
	if (writer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
	   writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true); 
	DOMElement *pobjElemToWrite = m_pobjDomTree->getDocumentElement();
	pszXmlOutput =
XMLString::transcode(writer->writeToString(*pobjElemToWrite));

        printf( "XML Output: %s\n", pszXmlOutput );


Cheers
Jim



Alberto Massari wrote:
> 
> Hi Jim,
> at this point, if the feature gets set but the 
> output still isn't pretty-printed, could you post the code you are using?
> 
> Alberto
> 
> At 01.55 19/09/2006 -0700, fatboyjim wrote:
> 
>>Thanks for the replies, however, they just don't work for me (although the
>>writer feature does get set).
>>
>>The output is on one line, with no indents or whitespace
>>
>>Any ideas?
>>
>>Thanks
>>Jim
>>
>>
>>Matteo Vega wrote:
>> >
>> >
>> > Hi,
>> >
>> > After you create the DOM writer, set this feature.
>> >
>> > if
>> > (theDomWriter->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
>> > true))
>> >
>> > theDomWriter->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
>> > true);
>> >
>> > You also might wanna look at DOMPrint example. There
>> > is a good implementation of this in there.
>> >
>> > Cheers,
>> >
>> >
>> > Matt.
>> >
>> >
>> > --- Florent Philippe <ph...@yahoo.fr> wrote:
>> >
>> >> lol I asked the same a few days ago
>> >> something to do with xmlprettyoutput thing
>> >> google : "xerce-c" xml pretty output
>> >>
>> >> regs
>> >> phil
>> >>
>> >>
>> >> ----- Message d'origine ----
>> >> De : fatboyjim <fa...@hotmail.com>
>> >> À : c-users@xerces.apache.org
>> >> Envoyé le : Mercredi, 13 Septembre 2006, 6h50mn 59s
>> >> Objet : Print XML from DOM tree
>> >>
>> >>
>> >> Hi all,
>> >>
>> >> I am able to write XML to a string using a DOMWriter
>> >> and the writeToString()
>> >> method.
>> >>
>> >> This works fine. I am wondering, is there a way to
>> >> get 'prettier' output?
>> >> ie. a new line after each element, and an extra
>> >> indent between child
>> >> elements, like XML is displayed in Internet Explorer
>> >> etc
>> >>
>> >> Thanks for your time
>> >>
>> >> Jim
>> >> --
>> >> View this message in context:
>> >>
>> > http://www.nabble.com/Print-XML-from-DOM-tree-tf2266523.html#a6289687
>> >> Sent from the Xerces - C - Users forum at
>> > Nabble.com.
>> >
>> >
>> > __________________________________________________
>> > Do You Yahoo!?
>> > Tired of spam?  Yahoo! Mail has the best spam protection around
>> > http://mail.yahoo.com
>> >
>> >
>>
>>--
>>View this message in context: 
>>http://www.nabble.com/Print-XML-from-DOM-tree-tf2266523.html#a6384289
>>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Print-XML-from-DOM-tree-tf2266523.html#a7091735
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Re : Print XML from DOM tree

Posted by Alberto Massari <am...@datadirect.com>.
Hi Jim,
at this point, if the feature gets set but the 
output still isn't pretty-printed, could you post the code you are using?

Alberto

At 01.55 19/09/2006 -0700, fatboyjim wrote:

>Thanks for the replies, however, they just don't work for me (although the
>writer feature does get set).
>
>The output is on one line, with no indents or whitespace
>
>Any ideas?
>
>Thanks
>Jim
>
>
>Matteo Vega wrote:
> >
> >
> > Hi,
> >
> > After you create the DOM writer, set this feature.
> >
> > if
> > (theDomWriter->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
> > true))
> >
> > theDomWriter->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
> > true);
> >
> > You also might wanna look at DOMPrint example. There
> > is a good implementation of this in there.
> >
> > Cheers,
> >
> >
> > Matt.
> >
> >
> > --- Florent Philippe <ph...@yahoo.fr> wrote:
> >
> >> lol I asked the same a few days ago
> >> something to do with xmlprettyoutput thing
> >> google : "xerce-c" xml pretty output
> >>
> >> regs
> >> phil
> >>
> >>
> >> ----- Message d'origine ----
> >> De : fatboyjim <fa...@hotmail.com>
> >> À : c-users@xerces.apache.org
> >> Envoyé le : Mercredi, 13 Septembre 2006, 6h50mn 59s
> >> Objet : Print XML from DOM tree
> >>
> >>
> >> Hi all,
> >>
> >> I am able to write XML to a string using a DOMWriter
> >> and the writeToString()
> >> method.
> >>
> >> This works fine. I am wondering, is there a way to
> >> get 'prettier' output?
> >> ie. a new line after each element, and an extra
> >> indent between child
> >> elements, like XML is displayed in Internet Explorer
> >> etc
> >>
> >> Thanks for your time
> >>
> >> Jim
> >> --
> >> View this message in context:
> >>
> > http://www.nabble.com/Print-XML-from-DOM-tree-tf2266523.html#a6289687
> >> Sent from the Xerces - C - Users forum at
> > Nabble.com.
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
> >
>
>--
>View this message in context: 
>http://www.nabble.com/Print-XML-from-DOM-tree-tf2266523.html#a6384289
>Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Re : Print XML from DOM tree

Posted by fatboyjim <fa...@hotmail.com>.
Thanks for the replies, however, they just don't work for me (although the
writer feature does get set).

The output is on one line, with no indents or whitespace

Any ideas?

Thanks
Jim


Matteo Vega wrote:
> 
> 
> Hi,
> 
> After you create the DOM writer, set this feature.
> 
> if
> (theDomWriter->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
> true))
>                
> theDomWriter->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
> true);
> 
> You also might wanna look at DOMPrint example. There
> is a good implementation of this in there.
> 
> Cheers,
> 
> 
> Matt.
> 
> 
> --- Florent Philippe <ph...@yahoo.fr> wrote:
> 
>> lol I asked the same a few days ago
>> something to do with xmlprettyoutput thing
>> google : "xerce-c" xml pretty output
>>  
>> regs
>> phil
>> 
>> 
>> ----- Message d'origine ----
>> De : fatboyjim <fa...@hotmail.com>
>> À : c-users@xerces.apache.org
>> Envoyé le : Mercredi, 13 Septembre 2006, 6h50mn 59s
>> Objet : Print XML from DOM tree
>> 
>> 
>> Hi all,
>> 
>> I am able to write XML to a string using a DOMWriter
>> and the writeToString()
>> method.
>> 
>> This works fine. I am wondering, is there a way to
>> get 'prettier' output?
>> ie. a new line after each element, and an extra
>> indent between child
>> elements, like XML is displayed in Internet Explorer
>> etc
>> 
>> Thanks for your time
>> 
>> Jim
>> -- 
>> View this message in context:
>>
> http://www.nabble.com/Print-XML-from-DOM-tree-tf2266523.html#a6289687
>> Sent from the Xerces - C - Users forum at
> Nabble.com.
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> 

-- 
View this message in context: http://www.nabble.com/Print-XML-from-DOM-tree-tf2266523.html#a6384289
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Re : Print XML from DOM tree

Posted by Matteo Vega <ve...@yahoo.com>.
Hi,

After you create the DOM writer, set this feature.

if
(theDomWriter->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true))
               
theDomWriter->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
true);

You also might wanna look at DOMPrint example. There
is a good implementation of this in there.

Cheers,


Matt.


--- Florent Philippe <ph...@yahoo.fr> wrote:

> lol I asked the same a few days ago
> something to do with xmlprettyoutput thing
> google : "xerce-c" xml pretty output
>  
> regs
> phil
> 
> 
> ----- Message d'origine ----
> De : fatboyjim <fa...@hotmail.com>
> À : c-users@xerces.apache.org
> Envoyé le : Mercredi, 13 Septembre 2006, 6h50mn 59s
> Objet : Print XML from DOM tree
> 
> 
> Hi all,
> 
> I am able to write XML to a string using a DOMWriter
> and the writeToString()
> method.
> 
> This works fine. I am wondering, is there a way to
> get 'prettier' output?
> ie. a new line after each element, and an extra
> indent between child
> elements, like XML is displayed in Internet Explorer
> etc
> 
> Thanks for your time
> 
> Jim
> -- 
> View this message in context:
>
http://www.nabble.com/Print-XML-from-DOM-tree-tf2266523.html#a6289687
> Sent from the Xerces - C - Users forum at
Nabble.com.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re : Print XML from DOM tree

Posted by Florent Philippe <ph...@yahoo.fr>.
lol I asked the same a few days ago
something to do with xmlprettyoutput thing
google : "xerce-c" xml pretty output
 
regs
phil


----- Message d'origine ----
De : fatboyjim <fa...@hotmail.com>
À : c-users@xerces.apache.org
Envoyé le : Mercredi, 13 Septembre 2006, 6h50mn 59s
Objet : Print XML from DOM tree


Hi all,

I am able to write XML to a string using a DOMWriter and the writeToString()
method.

This works fine. I am wondering, is there a way to get 'prettier' output?
ie. a new line after each element, and an extra indent between child
elements, like XML is displayed in Internet Explorer etc

Thanks for your time

Jim
-- 
View this message in context: http://www.nabble.com/Print-XML-from-DOM-tree-tf2266523.html#a6289687
Sent from the Xerces - C - Users forum at Nabble.com.