Chamoro new version of XML parser

xiaoxiao2021-03-06  128

Chamoro instructions

Mainly divided into three parts:

1.XML Structure Operation Section General Node Selection, Establish, Query, Delete, and Property Management 2.xml Data Analysis section parsing XML Raw data into XML Structure 3.XML Data Source Row section provides a variety of data sources, support memory String, file, pipe, socket, etc.

Before you say it, you need to express it, Charmoro does not fully support the XML1.0 specification, just a small part, and support for Chinese characters. This version has not joined Unicode support, which is different from the original TXML, so when processing Chinese characters I hope you can test it yourself, but the support for GB2312 is very good :) In addition, XML 1.0 specification can only have a root node, but this parser supports multiple "root" nodes, that is, no The root node said that only the first node said, so if you want to work with other parsers, you need to pay attention to this try not to write a number of "root" nodes (in Xml1.0, not counting The node, so, you can have a number of comments, but try to make few "root" nodes)

Let me talk about the first part: Chamoro supports the type:

ENUM NODETYPE {Declare, / * Declaration * / Dispose, / * Process :) * / Node, / * Node * / Comment, / * Note * / Hold, / * Original * / unknow / * unknown * /};

(1) .Declare, / * Declaration * /? This line (2) .dispose, / * handling * / This version is temporarily not supported, Generally, it is (3) .node, / * node * / this is the most common node of XML, including attributes (4) .comment, / * comment * / Comment Node (5). Hold / * is the same as " "* / cdata value, this node and basic functions are the same, different is node The value does not need to be escaped (about the content of the escape, I will add it later) mainly two structural struct tagqxml {qstringlist m_listdeclare; / * announced linked list, store qstring :) * / qxmlnode * m_noderoot; int m_nerrorcode Qxmlvtbl * lpvtbl; unsigned long m_nrow;}; tagqxml is the basic structure of XML, the general call method is QXML XML = newqxml (); if needed, then qxml * xml = mallocqxml () ;

PS: The call method of this program is basically like this, the call method is a bit weird :)

The main function of QXML is: typedef struct qxmlvtbl {qxmlnode * (* toroot) (qxml * self); qxml * self, char * filename); int (* ParseBuff) (QXML * Self, Char * Buff ); Int (* savetofile) (qxml * self, char * filename); char * (* geterrtext) (qxml * self); int (* getDeclared, qstring * data); void (* release) QXML * Self);} QXMLVTBL;

It is the pointer function call like this XML.lpvTBL-> Toroot (& XML);

The role of Toroot is to a node, which is not considered a parsefile parsing a file name.

ParseBuff parsing a string

SaveTofile saves the parsing content into files

Geterrtext um. This is not yet: P

GetDeclaredata is a string of the declaration. Release is released. In the entire program, in addition to QXML can release other like QXMLNode, please do not manually release (should design the corresponding deletion or elimination function)! Manage yourself by qxml

:( C language security is not C good

This is normal XML call, which is parsing. Save.

Of course. You can maintain or create an XML file by operating Node

The structure of QXMLNode is as follows

Struct tagqxmlnode {qstring m_szname; qstring m_szvalue; int m_ntype; qlist m_listattrib;

Qxmlnode * m_nodecled; qxmlnode * m_nodenext; QXMLNode * m_nodeparent;

QXMLNodevTBL * lpvtbl;};

This is a relatively typical tree structure call and how the method is similar, but the function is different, I will tell the main function.

Typedef struct {

QxmlNode * (* Toparent) (qxmlnode * self); // Returns the parent node, if it is empty, it should be "root" node qxmlnode * (* tochild) (qxmlnode * self, char * name); // 到 子 网If Name is empty. To the first node, qxmlnode * (* TonextNode) (qxmlnode * self, char * name); // Next node, if Name is empty. Just next node. Otherwise, next Name Node qxmlnode * (* toprevnode) (qxmlnode * self, char * name); //, different, different, to the previous node qxmlnode * (* TofirstChild) (qxmlnode * self); // to the first child node qxmlnode * (* Tolastchild) (qxmlnode * self); // to the last child node BOOL (* addchild) (QXMLNode * Self, Char * name, char * value); // Increase child node BOOL (* addnodeTochild) (QXMLNode * Self, qxmlnode * node); // Additional child node to the end, bool (* setnodeName) (QXMLNode * Self, Char * name);

Bool (* setnodevalue) (QXMLNode * Self, Char * Value);

Char * (* getnodename) (qxmlnode * self); qxmlnode * self); int (* getnode qi) (qxmlnode * self); int (* getnode * self) (QxmlNode * Self, QString * data, int DEPTH);

Bool (* setttrib) (qxmlnode * self, char * name, char * value); // The same name will be overwritten Value Char * (* GetAttrib) (qxmlnode * self, char * name); BOOL (* Removeattrib) ( QXMLNODE * SELF, CHAR * name); Void (* Destory) (qxmlnode * self); // Eliminate a node void (* release * self); // Do not call this function} QXMLNodeVTBL;

Specific examples, you can take a look at the GetNodedata's function in Qxml.c. Side, only five kinds, & "<>" five,

: (I have to go to work. Otherwise it will be late and have the same hobby. Add this together. Do this better, fully support Unicode and DTD

Up. Give God

MSN: 31-BOY@163.com

转载请注明原文地址:https://www.9cbs.com/read-99897.html

New Post(0)