The XML Parser of the new version of Chamoro

Source: Internet
Author: User
Tags xml parser

Chamoro instructions

It consists of three parts:

1. XML structure operation section
Common node selection, creation, query, deletion, and attribute Management
2. XML data parsing
Parse XML raw data into XML structure
3. XML Data Source Operation
Provides multiple data sources, including strings, files, pipe, and socket in the memory.

Before that, we need to briefly describe that charmoro does not fully support the xml1.0 specification, but it is only a small part. In addition,
Support for Chinese characters. Unicode is not supported in this version, which is different from the original txml. Therefore, when processing Chinese characters,
I hope you can test it on your own, but the support for gb2312 is good.
In addition, XML 1.0 requires only one root node, but this parser supports multiple "root" nodes, that is,
There is no root node, but only the first node. Therefore, if you want to work with other Resolvers, pay attention
Try not to write multiple "root" nodes (comments in xml1.0 are not counted as nodes, so you can have multiple
Note, but try to reduce the number of "root" nodes)

Let's talk about the first part:
The following types are supported by Chamoro:

Enum nodetype
{
Declare,/* Declaration */
Dispose,/* process */
Node,/* node */
Comment,/* Comment */
Hold,/* unchanged */
Unknow/* unknown */
};

 
(1). Declare,/* Declaration */That is, <? XML version = "1.0"?> This line
(2). Dispose,/* Processing */This version is not currently supported. Generally, it is set to <! Or <? But not
Not Declaration (<? XML) or comment <?>
(3). node,/* node */is the most common node in XML, including attributes
(4). Comment,/* Comment */comment nodes to "<! -- "Start and end with" -->"
(5). Hold/* unchanged */CDATA value. The basic functions of this node and <node> are the same. What is different?
Node values do not need to be escaped (I will add the escape content later)
Mainly two struct
Struct tagqxml
{
Qstringlist m_listdeclare;/* declared linked list, storing qstring */
Qxmlnode * m_noderoot;
Int m_nerrorcode;
Qxmlvtbl * lpvtbl;
Unsigned long m_nrow;
Unsigned long m_ncol;
};
Tagqxml is the basic structure of XML, and the general call method is
Qxml xml = newqxml ();
If the pointer structure is required, use
Qxml * xml = mallocqxml ();

PS: ThisProgramThe calling method is basically like this, and the calling method is a little strange

The main functions of qxml are as follows:
Typedef struct qxmlvtbl {
Qxmlnode * (* toroot) (qxml * Self );
INT (* parsefile) (qxml * Self, char * filename );
INT (* parsebuff) (qxml * Self, char * buff );
INT (* savetofile) (qxml * Self, char * filename );
Char * (* geterrtext) (qxml * Self );
INT (* getdeclaredata) (qxml * Self, qstring * data );
Void (* release) (qxml * Self );
} Qxmlvtbl;

Yes, pointer function calls are like this.
XML. lpvtbl-> toroot (& XML );

The role of toroot is to reach a node, declaring that it is not the first node
Parsefile resolves a file name

Parsebuff parses a string

Savetofile saves the parsed content as a file

Geterrtext. Well, this is not done yet.

Getdeclaredata is the string that generates the declaration.

Release is the release. In the whole program, apart from qxml
Do not release them manually (the corresponding deletion or elimination function should be designed )! Managed by qxml

C language security means it is not as good as C ++

This is a normal XML call, that is, parsing and saving.

Of course, you can operate node to maintain or create an XML file.

The structure of qxmlnode is as follows:

Struct tagqxmlnode
{
Qstring m_szname;
Qstring m_szvalue;
Int m_ntype;
Qlist m_listattrib;

Qxmlnode * m_nodechild;
Qxmlnode * m_nodenext;
Qxmlnode * m_nodeprev;
Qxmlnode * m_nodeparent;

Qxmlnodevtbl * lpvtbl;
};

This is a typical tree structure.
The calling and operation methods are similar to qxml, but the functions are different. Let's talk about the main functions.

 

Typedef struct qxmlnodevtbl {

qxmlnode * (* toparent) (qxmlnode * Self);
// return the parent node. If it is null, it should be the "root" node
qxmlnode * (* tochild) (qxmlnode * Self, char * Name);
// to the subnode, if name is empty. to the first node,
qxmlnode * (* tonextnode) (qxmlnode * Self, char * Name);
// next node, if name is empty. to the next node. otherwise, the node to the next name
qxmlnode * (* toprevnode) (qxmlnode * Self, char * Name);
// same as above, the difference is that to the previous node
qxmlnode * (* tofirstchild) (qxmlnode * Self);
// to the first subnode
qxmlnode * (* tolastchild) (qxmlnode * Self);
// to the last subnode
bool (* addchild) (qxmlnode * Self, char * Name, char * value );
// Add a subnode
bool (* addnodetochild) (qxmlnode * Self, qxmlnode * node);
// append a subnode to the end,
bool (* setnodename) (qxmlnode * Self, char * Name);

Bool (* setnodevalue) (qxmlnode * Self, char * value );

Char * (* getnodename) (qxmlnode * Self );
Char * (* getnodevalue) (qxmlnode * Self );
INT (* getnodetype) (qxmlnode * Self );
INT (* getnodedata) (qxmlnode * Self, qstring * data, int depth );

Bool (* setattrib) (qxmlnode * Self, char * Name, char * value );
// Values with the same name will be overwritten
Char * (* getattrib) (qxmlnode * Self, char * Name );
Bool (* removeattrib) (qxmlnode * Self, char * Name );
Void (* destory) (qxmlnode * Self );
// Delete a node
Void (* release) (qxmlnode * Self );
// Do not call this function normally
} Qxmlnodevtbl;

For more information, see the getnodedata function in qxml. C.
Only five escape types are supported. & "'<> these five types are supported,

I'm going to work. Otherwise I will be late.

And then join with others who share the same interests to make it better and fully support Unicode and DTD.

Up. daze God

MSN: 31-boy@163.com

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.