⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xml_util.cpp

📁 j2me is based on j2mepolish, client & server for mobile application.
💻 CPP
字号:
/*
www.sourceforge.net/projects/tinyxpath_
Copyright (c) 2002-2004 Yves Berquin (yvesb@users.sourceforge.net)

This software is provided 'as-is', without any express or implied
warranty. In no_ event will the authors be held liable for any
damages arising from the use of this software.

Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.
*/

/**
   \file xml_util.cpp
   \author Yves Berquin
*/

#include "xml_util.h"

namespace aux { namespace xml
{

/// Cardinality in the terms of XPath counts from 1 for the first_ element_
int i_xml_cardinality (
   const element * XEp_elem,      ///< Base element_. Must not be null
   bool o_by_name)                     ///< true if we ask for the cardinality for our name_ only
{
	const node * XNp_parent;
	const element * XEp_child;
   TIXML_STRING S_name; 
	int i_res;

   assert (XEp_elem);
	XNp_parent = XEp_elem -> parent ();
	assert (XNp_parent);
   if (o_by_name)
   {
      S_name = XEp_elem -> value ();
	   XEp_child = XNp_parent -> first_child_element (S_name . c_str ());
	   i_res = 1;
	   while (XEp_child)
	   {
	      if (XEp_child == XEp_elem)
			   return i_res;
		   else
		   {
            i_res++;
			   XEp_child = XEp_child -> next_sibling_element (S_name . c_str ());
		   }
	   }
   }
   else
   {
	   XEp_child = XNp_parent -> first_child_element ();
	   i_res = 1;
	   while (XEp_child)
	   {
	      if (XEp_child == XEp_elem)
			   return i_res;
		   else
		   {
            i_res++;
			   XEp_child = XEp_child -> next_sibling_element ();
		   }
	   }
   }
	assert (false);
	return -1;
}

/// Family size : Nb of sibling elements (including ourselves)
int i_xml_family_size (
   const element * XEp_elem)   ///< Base element_. Must not be null 
{
	const element * XEp_child;
	const node * XNp_parent;
   int i_res;

   assert (XEp_elem);
	XNp_parent = XEp_elem -> parent ();
	assert (XNp_parent);
	XEp_child = XNp_parent -> first_child_element ();
   i_res = 0;
	while (XEp_child)
	{
      i_res++;
		XEp_child = XEp_child -> next_sibling_element ();
	}
	return i_res;
}

} }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -