From patchwork Tue Mar 8 16:36:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 63689 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2130389lbc; Tue, 8 Mar 2016 08:39:38 -0800 (PST) X-Received: by 10.140.30.245 with SMTP id d108mr38180090qgd.31.1457455177127; Tue, 08 Mar 2016 08:39:37 -0800 (PST) Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com. [209.132.183.39]) by mx.google.com with ESMTPS id w132si3706222qka.53.2016.03.08.08.39.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Mar 2016 08:39:37 -0800 (PST) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u28GaqCI000931; Tue, 8 Mar 2016 11:36:52 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u28GapSm012377 for ; Tue, 8 Mar 2016 11:36:51 -0500 Received: from colepc.redhat.com (ovpn-113-126.phx2.redhat.com [10.3.113.126]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u28GalpS004012; Tue, 8 Mar 2016 11:36:50 -0500 From: Cole Robinson To: libvirt-list@redhat.com Date: Tue, 8 Mar 2016 11:36:35 -0500 Message-Id: <728ba278f42eb1b900ac43f05d388d31e88c932f.1457454944.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-loop: libvir-list@redhat.com Cc: Andrea Bolognani Subject: [libvirt] [PATCH 4/8] util: xml: add virXMLPropertyCount X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com Returns an integer count of the number of XML properties an element has. Will be used in future patches. --- src/util/virxml.c | 17 +++++++++++++++++ src/util/virxml.h | 1 + 2 files changed, 18 insertions(+) -- 2.5.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/util/virxml.c b/src/util/virxml.c index 489bad8..86c021c 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -890,6 +890,23 @@ virXMLChildElementCount(xmlNodePtr node) return ret; } +/* Returns the number of node's properties, or -1 on error. */ +long +virXMLPropertyCount(xmlNodePtr node) +{ + long ret = 0; + xmlAttrPtr cur = NULL; + + if (!node || node->type != XML_ELEMENT_NODE) + return -1; + cur = node->properties; + while (cur) { + ret++; + cur = cur->next; + } + return ret; +} + /** * virXMLNodeToString: convert an XML node ptr to an XML string diff --git a/src/util/virxml.h b/src/util/virxml.h index b94de74..5cf082e 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -72,6 +72,7 @@ int virXPathNodeSet(const char *xpath, char * virXMLPropString(xmlNodePtr node, const char *name); long virXMLChildElementCount(xmlNodePtr node); +long virXMLPropertyCount(xmlNodePtr node); /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode,