Mini-XML入門基礎Getting Started with Mini-XML c


Mini-XML入門基礎Getting Started with Mini-XML
This chapter describes how to write programs that use Mini-XML to access data in an XML file. Mini-XML provides the following functionality:
[主な内容は、Mini-XMLを使用してC++プログラムを自分で書く方法でXMLファイルデータにアクセスまたは制御する方法です.具体的には以下の通りです.]
Functions for creating and managing XML documents in memory.
[システムメモリにおけるXMLファイルの作成と管理]Reading of UTF-8 and UTF-16 encoded XML files and strings.
[UTF-8とUTF-16でエンコードされたXMLファイルと文字列を読み込む]Writing of UTF-8 encoded XML files and strings.
[書込UTF-8符号化XMLファイルと文字列]Support for arbitrary element names, attributes, and attribute values with no preset limits, just available memory.
〔任意の方法で決定された要素名、属性、属性値をサポートします.W 3 C基準でなくてもいいですか?メモリが使用可能であることを前提としています)Support for integer, real, opaque ("cdata"), and text data types in "leaf"nodes.
〔サブノードにおける整数、浮動小数点、文字データ(CDATA)、テキストなどのデータ型の使用をサポートする〕"Find", "index", and "walk"functions for easily accessing data in an XML document.
〔find、index、walk関数はxmlファイルのデータに簡単にアクセスできます.〕
Mini-XML doesn't do validation or other types of processing on the data based upon schema files or other sources of definition information, nor does it support character entities other than those required by the XML specification.
〔XML schemaは、XMLドキュメントを定義するための合法的な構築モジュールであり、DTDのようなものであるが、Mini-XMLはXML Schemaに基づくデータの検証やその他の処理を行わず、文字エンティティもサポートせず、もちろんXML仕様の要求をサポートしなければならない.〕
The Basics
Mini-XML provides a single header file which you include:
#include <mxml.h>

The Mini-XML library is included with your program using the -lmxml option:
gcc -o myprogram myprogram.c -lmxml ENTER

If you have the pkg-config(1) software installed, you can use it to determine the proper compiler and linker options for your installation:
pkg-config --cflags mxml ENTER
pkg-config --libs mxml ENTER

Nodes
Every piece of information in an XML file (elements, text, numbers) is stored in memory in "nodes". Nodes are defined by the mxml_node_t structure. The type member defines the node type (element, integer, opaque, real, or text) which determines which value you want to look at in the value union.〔XMLファイルの各ブロック情報は「ノード」として格納され、Mini-XMLではノードはmxml_node_t構造体定義、mxml_node_tのtypeメンバーはノードタイプを定義し、ノードタイプはvalue共同体でクエリーする値のタイプを決定します.次の表はmxml_node_tのmxml_value_tメンバーのメンバー.]
Table 2-1: Mini-XML Node Value Members
Value
Type
Node member
Custom
void *
node->value.custom.data
Element
char *
node->value.element.name
Integer
int
node->value.integer
Opaque (string)
char *
node->value.opaque
Real
double
node->value.real
Text
char *
node->value.text.string
mxml_node_s An XML node. struct mxml_node_s {  struct mxml_node_s *child;  struct mxml_node_s *last_child;  struct mxml_node_s *next;  struct mxml_node_s *parent;  struct mxml_node_s *prev;  int ref_count;  mxml_type_t type;  void *user_data;  mxml_value_t value;  };
 
  Members
child
First child node
last_child
Last child node
next
Next node under same parent
parent
Parent node
prev
Previous node under same parent
ref_count
Use count
type
Node type
user_data
User data
value
Node value
Each node also has a user_data member which allows you to associate application-specific data with each node as needed.
[各ノード構造体mxml_node_tにはuser_も含まれているdataメンバーです.これにより、各ノードが必要に応じて特定のアプリケーションに関連するデータを関連付けることができます.]
New nodes are created using the mxmlNewElement, mxmlNewInteger, mxmlNewOpaque, mxmlNewReal, mxmlNewText mxmlNewTextf mxmlNewXML functions. Only elements can have child nodes, and the top node must be an element, usually the  node created by mxmlNewXML().
[新しいノードはmxmlNewElement,mxmlNewInteger,mxmlNewOpaque,mxmlNewReal,mxmlNewText,mxmlNewTextf,mxmlNewXML関数を使用して作成されます.以上は要素(element)のみがサブノードを持つことができ、ルートノードは要素でなければなりません.この要素はノードであり、mxmlNewXMLを使用して作成されます.]
Nodes have pointers to the node above (parent), below ( child), left (prev), and right (next) of the current node. If you have an XML file like the following:
[ノード構造体には、自身の上位ノード(parent)、サブノード(child)、隣接する前ノード(prev)、および隣接する次ノード(next)を指すポインタがある.具体例は以下の通りである.]
<?xml version="1.0"?>
<data>
<node>val1</node>
<node>val2</node>
<node>val3</node>
<group>
<node>val4</node>
<node>val5</node>
<node>val6</node>
</group>
<node>val7</node>
<node>val8</node>
</data>

the node tree for the file would look like the following in memory:
[システムメモリ内のxmlファイルノードツリーは次のように見えます.]
?xml
|
data
|
node - node - node - group - node - node
| | | | | |
val1 val2 val3 | val7 val8
|
node - node - node
| | |
val4 val5 val6

where "-"is a pointer to the next node and "|"is a pointer to the first child node.
〔上の"-"は隣接ノードを指すポインタを表し、"|"は第1のサブノードを指すポインタを表す.〕
Once you are done with the XML data, use the mxmlDelete function to recursively free the memory that is used for a particular node or the entire tree:
〔XMLデータの操作が完了すると、mxmlDelete関数を使用してメモリを解放し、ノードツリー上の各ノードが使用するメモリを反復的に解放することができます. ]
mxmlDelete(tree);

    :http://hi.baidu.com/zhmsong/blog/item/9b35eb601402f6d48db10dde.html