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

Re: [libvirt] [PATCH 01/14] snapshot: indent domain xml when nesting, round 1



On Tue, Sep 27, 2011 at 06:50:23AM -0600, Eric Blake wrote:
> On 09/27/2011 03:03 AM, Daniel P. Berrange wrote:
> >On Thu, Sep 22, 2011 at 02:34:55PM -0600, Eric Blake wrote:
> >>Future patches can take advantage of this to generate nicer
> >>XML output with parameterizable indentation.
> >
> >
> >Hmm, is there any way we can work with virBuffer so that we don't
> >need to pass an indent level to every single API call ?
> >
> >eg, can we have something which lets us do
> >
> >    virBufferSetIndent(buf, "     ");
> >
> >and then it will automagically prepend that indent every time
> >a API call is made following a newline. If we could do this,
> >then pretty much all of your patches would disappear
> 
> I think there's still some other aspects in the other patches that
> may mean that things won't disappear entirely, but I like the idea.
> I see several potential usage styles:
> 
> virBufferIndent...(indent, "<parent>\n");
> virBufferIndent...(indent + 2, "<child/>\n");
> virBufferIndent...(indent, "</parent>\n");
> 
> or
> 
> virBufferAddIndent(indent);
> virBuffer...("<parent>\n");
> virBuffer...("  <child/>\n");
> virBuffer...("</parent>\n");
> virBufferAddIndent(-indent);
> 
> or
> 
> virBufferAddIndent(indent);
> virBuffer...("<parent>\n");
> virBufferAddIndent(2);
> virBuffer...("<child/>\n");
> virBufferAddIndent(-2);
> virBuffer...("</parent>\n");
> virBufferAddIndent(-indent);


I was thinking of the middle option here. I think it is visually helpful
to still see the indentation in our API calls thus:

  virBuffer...("<parent>\n");
  virBuffer...("  <child/>\n");
  virBuffer...("</parent>\n");

IMHO we should just focus on addressing the use case of embedding one XML
tree inside another independantly generated XML tree. There are a couple
of places where we need todo this:

  - Generating the state XML for /var/run/libvirt/qemu/$GUEST.xml
  - Embedding storage encryption data
  - Embedding domain XML in snapshot XML


If we really want to be able to simplify indentation for all our XML
building internal APIs, then arguably we should stop using virBuffer
completely, and create a simple XML DOM like API for constructing
documents.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


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