Use the L scripting language to develop an XML access library.

Source: Internet
Author: User

Use the L scripting language to develop an XML access library.

XML is currently the most widely used data exchange format

Then we will use the L script language to develop an XML access library.

The script file below is a simple XML file access library, which can generate a simple XML file

# Scplib
Definition: Class, XML file
Start: Class, XML file

Definition: String, XML File Header

Definition: String, file body

Definition: String, start tag, "<"

Definition: String, line end label, "/>"

Definition: String, end tag, ">"

Definition: String, paragraph end label


Definition: function, insert file header, File Header

Start: function. Insert a file header.

# Clear: String, XML File Header

# Connection: String, XML file header, and file header

Clear: String, file body

Connection: String, file body, File Header

Display: file body

End: function, insert File Header


Definition: function, add node, node name

Start: function, add Node

Definition: String, node content

Connection: String, node content, start tag

Connection: String, node content, node name

Connection: String, node content ,""

Connection: String, node content, end tag

Connection: String, node content, start tag

Connection: String, node content ,"/"

Connection: String, node content, node name

Connection: String, node content, end tag

Connection: String, file body, node content

Display: file body

End: function, add Node


Definition: function, add a subnode, node name, And subnode name

Start: function. Add a subnode.

Definition: string at the end of the node

Connection: String, end of the node, start tag

Connection: String, end of the node ,"/"

Connection: String, end of the node, and node name

Connection: String, tail of the node, and end tag

Definition: integer, tail position, 0

Search: String, file body, node tail, tail location


Definition: String, node content

Connection: String, node content, start tag

Connection: String, node content, subnode name

Connection: String, node content ,""

Connection: String, node content, end tag

Connection: String, node content, start tag

Connection: String, node content ,"/"

Connection: String, node content, subnode name

Connection: String, node content, end tag


If: tail position> = 0, insert: String, file body, node content, tail position

Display: file body

End: function, add subnode



Definition: function, add node value, node name, node Value

Start: function, add node Value

Definition: string at the end of the node

Connection: String, end of the node, start tag

Connection: String, end of the node ,"/"

Connection: String, end of the node, and node name

Connection: String, tail of the node, and end tag

Definition: integer, tail position, 0

Search: String, file body, node tail, tail location

If: tail position> = 0, insert: String, file body, node value, tail position

Display: file body

End: function, add node Value


Definition: function, add attribute, node name, attribute name, attribute value

Start: function. Add attributes.

Definition: String, start of a node

Connection: String, node start, start tag

Connection: String, node start, node name


Definition: integer, starting position, 0

Definition: integer, length of the Start Node, 0

Size: String, node start, and node start Length

Definition: String, attribute body ,""

Connection: String, attribute body, attribute name

Connection: String, attribute body, ="

Connection: String, attribute body, attribute value

Connection: String, attribute body ,"\""

Search: String, file body, node start, start position

Calculation: Start position = start position + start length of the node

If: Start position> = 0, insert: String, file body, attribute body, start position

Display: file body

End: function, add attribute


Definition: function, saved as a file, file name

Start: function, saved as a file

Delete: file, file name

Open: file, file1, file name

Write: file, file1, file body

End: function, saved as a file

End: Class, XML file

The following script references the self-implemented XML library and instantiates an XML class.

# Scp
Import: Library, E: \ ScriptEngine \ Scripts \ xmllib. scp


Definition: String, common XML file header, <? Xml version = "1.0" encoding = "UTF-8" standalone = "yes"?>
# Instantiate an XML file object
Definition: XML file, my XML file
Call: My XML file: function, insert file header, General XML File Header
Call: My XML file: function, add node, html
# Call: My XML file: function, add node value, html, I am an HTML file
Call: My XML file: function, add attribute, html, version, 1.0
Call: My XML file: function, add sub-nodes, html, book
Call: My XML file: function, add sub-nodes, html, price
Call: My XML file: function, add attribute, book, name, "C ++"
Call: My XML file: function, add attribute, price, value, 100.00
Call: My XML file: function, saved as a file, c: \ 1.xml
Definition: String, str1
Waiting: user input, str1


Interpreter engine Github https://github.com/zhaoliangcn/LScript

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.