Using LIBXML2 to implement ossim XML rule (rule) construction

Source: Internet
Author: User
Tags xml attribute ossim

At present, in the study of Ossim, there is an XML rule file on which the alarm is generated. These files are XML-tree-structured, and the following issues are encountered when investigating how to generate such XML rules using the LIBXML2 API:

1. LIBXML2 API which is the interface for constructing XML?

1) Use xmlNewNode to create a new node with the node pointer xmlnodeptr.

2) Add new properties to the node using Xmlnewprop

3) Note that the XML attribute values are Xmlchar * (that is, char *), you can use the Bad_cast macro directly, when adding a numeric Type property value

You need to convert to a string first.

4) Use Xmladdchild to add a child node to the node and continue to add grandchild nodes on the child node.

2. How does the LIBXML2 API put the constructed rule output to the screen view?

1) After constructing the good one XML structure, if you need to output to the screen to see the results, you can use the Xmldocdumpformatmemory interface

3. How does the LIBXML2 API write a well-constructed rule to an XML file?

1) If you need to write a well-constructed XML structure, create a file pointer in advance: Use interface Xmlnewdoc, pointer type: XMLDOCPTR

2) construct a root node using xmlNewNode, and use Xmldocsetrootelement to hang the root node on the file pointer.

3) The rest of the child node, grandson node directly hanging on the root node above OK.

4, the structure of the tree rule in the screen output, is a clear hierarchy, why write to the file there is no hierarchy?

1) There are many interfaces for libxml2 writing files:

Xmlsavefile: Only need to enter a file path and the current node pointer, in fact, the call is also Xmlsaveformatfile, but the default format is 0.

Xmlsaveformatfile: In addition to entering the above two parameters also need to increase the format (0/1 ... )

2) When the file format is 0 o'clock, write the file is not hierarchical, when format is 1 o'clock, write the XML structure of the file is a hierarchical tree structure.

5, the structure of multiple tree-shaped rules to save XML files, why will overwrite the original, how to solve it?

1) When constructing a tree-shaped XML structure, it is necessary to select the relevant LIBXML2 interface:

(1) When you are new to an XML file, add the root node using xmldocsetrootelement

(2) Continue to add new, side-by-side nodes in an XML file that already has one or more nodes, that is, the sibling node uses the Xmladdnextsibling interface

(3) If you need to delete a child node in a tree-shaped XML structure, first locate the root node in the structure, and then use the while loop to traverse each node.

Each node is joined together using the next pointer in the _XMLNODE structure body. Find the attribute value that needs to be judged by Xmlgetprop.

Use Xmlunlinknode and Xmlfreenode to delete this node.

Using LIBXML2 to implement ossim XML rule (rule) construction

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.