Re: [xml] How to add newlines to output?



list burtbicksler com wrote:
Hi,

New to libxml(2) and generally have things pretty well figured out but one issue that I haven't been able to work out is the following:

I am using the API to create a record of the form:
<root><first id="1"><child1>ChildData</child1><child2>ChildData</child2></first></root>

I would like the resulting xml when saved to a file to be formatted like this.
<root>
<first id="1">
<child1>ChildData</child1>
<child2>ChildData</child2>
</first>
</root>

I found a discussion in the archives that almost addresses this by referring to an FAQ entry #3 which says the preferred way is to generate the formatting yourself. I would like to do that but so far every API I have tried to use doesn't seem to accomplish what I need to get the resulting formatting.

What specific API, with a minimal example, needs to be used to add the newline (and optional spaces) after each node entry? If I have missed the specific API / example in the docs please point me to that area of the documentation.


const int indentTreeOutput = 1;
xmlSaveFormatFileEnc(filename, pDoc, "UTF-8", indentTreeOutput);

This is what I use to format my final file.

br,
Martin



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]