How to add newlines to output?

View: New views
4 Messages — Rating Filter:   Alert me  

How to add newlines to output?

by burtbick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.

Thanks,
Burt



_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@...
http://mail.gnome.org/mailman/listinfo/xml

Re: How to add newlines to output?

by slyght :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

As far as I know from my examples you need to generate an own node for a newline (textnode with content "\n").

Kind regards

2009/10/13 <list@...>
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.

Thanks,
Burt



_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@...
http://mail.gnome.org/mailman/listinfo/xml



_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@...
http://mail.gnome.org/mailman/listinfo/xml

Re: How to add newlines to output?

by Martin B.-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

list@... 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
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@...
http://mail.gnome.org/mailman/listinfo/xml

Parent Message unknown Re: How to add newlines to output?

by burtbick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the replies.

I was already doing the indent on saving, that isn't the issue.

I had already tried adding a text node.  First I tried:
xmlNewTextChild(newVersion, NULL, (xmlChar *)"", (xmlChar *)"\n");
That does insert the newline, but also gives me <> which I don't want.

Then I tried xmlTextConcat(newVersion, (xmlChar *)"\n", 1);  And different variants, and that didn't appear to insert any text or newlines.

So, what API do you use to add the new text nodes to insert the \n characters so that the human readable formatting of the xml file looks like:

<root>
 <record id="1">
 <child1>Data</child1>
 <child2>Data</child2>
 </record>
<record id="2">
<child1>Data</child>
<child2>Data</child>
</record>
</root>

Once I know exactly what API to use to add the /n and not get the <> then I should be set.

Thanks,
Burt


_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@...
http://mail.gnome.org/mailman/listinfo/xml