On Tue, Oct 18, 2011 at 12:39:34PM +0100, Daniel P. Berrange wrote: > On Fri, Oct 07, 2011 at 11:40:53AM +0200, Christophe Fergeau wrote: > > --- > > libvirt-gconfig/libvirt-gconfig-domain.c | 27 +++++++++++++++++++++++++++ > > libvirt-gconfig/libvirt-gconfig-domain.h | 1 + > > libvirt-gconfig/libvirt-gconfig.sym | 1 + > > 3 files changed, 29 insertions(+), 0 deletions(-) > > > > diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c > > index 7ae10b8..06fc3fa 100644 > > --- a/libvirt-gconfig/libvirt-gconfig-domain.c > > +++ b/libvirt-gconfig/libvirt-gconfig-domain.c > > @@ -130,3 +130,30 @@ char *gvir_config_domain_get_name(GVirConfigDomain *domain) > > return gvir_config_xml_get_child_element_content_glib(node, "name"); > > > > } > > + > > +void gvir_config_domain_set_name(GVirConfigDomain *domain, const char *name) > > +{ > > + xmlNodePtr parent_node; > > + xmlNodePtr old_node; > > + xmlNodePtr new_node; > > + xmlChar *encoded_name; > > + > > + parent_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(domain), > > + NULL); > > + encoded_name = xmlEncodeEntitiesReentrant(parent_node->doc, > > + (xmlChar *)name); > > + new_node = xmlNewDocNode(parent_node->doc, NULL, > > + (xmlChar *)"name", encoded_name); > > + xmlFree(encoded_name); > > + > > + old_node = gvir_config_xml_get_element(parent_node, "name", NULL); > > + > > + if (old_node) { > > + old_node = xmlReplaceNode(old_node, new_node); > > + xmlFreeNode(old_node); > > + } else { > > + xmlAddChild(parent_node, new_node); > > + } > > + > > + g_object_notify(G_OBJECT(domain), "name"); > > +} > > Perhaps we want another helper method for setting XML elements too. Yep this is planned, see https://gitorious.org/~teuf/libvirt/teuf-libvirt-glib/commit/264c6f952f02380ac21f379f0ddb2dc8cbb041fd for example > > In python-virtinst, they had a helper which allowed a very simple > xpath like use.eg > > gvir_config_xml_set_element(parent_node, "/name", node); > > Or > > gvir_config_xml_set_element(parent_node, "/foo/bar/name", node); > > automagically creating foo & bar in the process. Ah, interesting, my version is a bit more simplistic. > And setting NULL terminated list of attributes > > gvir_config_xml_set_element_attrs(parent_node, "/blah", > "someattr", "somevalue", > "otherattr", "othervalue", > NULL); yep, thought about that one too when adding some of the helpers, I'll come to it when I feel I'm duplicating too much code :) Christophe
Attachment:
pgpYIpPUtoPSS.pgp
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list