博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
NativeXml: A native Delphi XML parser and writer
阅读量:4596 次
发布时间:2019-06-09

本文共 5382 字,大约阅读时间需要 17 分钟。

This software component contains a small-footprint Object Pascal (Delphi) XML implementation that allows to read and write XML documents. You basically only need one unit and you can simply add it to the "uses" clause.

You can use this software to read XML documents from files, streams or strings. The load routine generates events that can be used to display load progress on the fly. You can also use it to create and save XML documents.

Features

    • Read XML directly from stringstream or file with fast parser (1Mb/sec on 1.5GHz P3), writes to string, stream and file even faster.
    • Import of all common tags, including comments, CDATA, XML declarations and stylesheets.
    • Load from streaming media is supported; you can set up events to work with the node data while it comes in. See example 1. No need to keep the whole XML document in memory! Works well for huge documents. This is the SAX-like approach.
    • Save to file, string or stream in readablepreserve or compact format. Readable format will add linefeeds and indents to make the file readable in a text editor. Compact format sticks to the Xml specification and adds minimal control characters. Preserve format keeps the markup of the document exactly as it was.
    • Directly add blobs or streams in the XML file, they will be encoded as Binhex or Base64 (but you don't have to worry about that).
    • Many native Delphi types can be stored directly to the nodes, making this code very suitable to use while writing storage methods.
      Store and load boolean, single, double, word, integer, string, TFont, TColor, TPen, TBrush, TDateTime.
      You don't have to worry about escaping the strings; this is done automatically.
    • Loads and saves ANSI, UTF-8 as well as Unicode (UTF-16) documents and implements proper conversion warnings. Recognises streams even without byte order marks. NativeXml works internally with UTF8 encoded strings to preserve extended characters, and supports widestrings.
    • Unique feature: Store, read and create any TPersistent object to/from XML directly (see Example5). This is done by iterating through all of the objects' published properties by use of RTTI (runtime type information). This feature is only available for D5 and up.
    • New! Now you can use the binary format of NativeXml. This avoids the expensive parsing process to get the textual xml data into the document (DOM). And even better, the binary file size is much smaller, ~50% of file size with uncompressed binary files, and ~15% of the file size in zlib-compressed files. And you can use AES encryption to keep your sensitive files safe from prying eyes.
      The interface is the same whether textual xml or binary xml files are used, so you can work with binary files for speed and size purposes, then always send them to the public as normal xml files. 
// TsdElementType enumerates the different kinds of elements that can be found  // in the XML document.  TsdElementType = (    xeElement,     //  0 normal element 
[value] [sub-elements]
xeAttribute, // 1 attribute ( name='value' or name="value") :
....
xeCharData, // 2 character data in a node :
char data
xeComment, // 3 comment
xeCData, // 4 literal data xeCondSection, // 5 conditional section
xeDeclaration, // 6 xml declaration
xeStylesheet, // 7 stylesheet
xeDocType, // 8 doctype dtd declaration xeDtdElement, // 9 dtd element
xeDtdAttList, // 10 dtd attlist
xeDtdEntity, // 11 dtd entity
xeDtdNotation, // 12 dtd notation
xeInstruction, // 13 processing instruction
xeWhiteSpace, // 14 chardata with only whitespace xeQuotedText, // 15 quoted text: "bla" or 'bla' xeEndTag, // 16
and signal function in binary xml xeError // 17 some error or unknown ); TsdElementTypes = set of TsdElementType;

 

// End-Of-Line style  TsdEolStyle = (    esLF,        // write End-Of-Line as just LF (#$0A) like normalised xml    esCRLF,      // write End-Of-Line as CR + LF (#$0D + #$0A), for the windows platform    esCR         // write End-Of-Line as CR (#$0D), for the mac platform  );
// Note on TNativeXml.XmlFormat:  // - xfCompact (default) to save the xml fully compliant and at smallest size  // - xfReadable writes additional nonsignificant whitespace so the client can easily read the xml file with a standard editor.  // - xfPreserve aims to preserve whitespace data just as it is parsed  TXmlFormatType = (    xfCompact,  // Save without any control chars except LF after declaration    xfReadable, // Save in readable format with indents and end-of-lines    xfPreserve  // Preserve whitespace whenever possible  );

 

{
NativeXmlNodes: Parsing and writing methods for XML nodes: Attribute, CDATA, CharData, Comment, Declaration, DocType, DTD-AttList, DTD-Element, DTD-Entity, DTD-Notation, Element, (processing) Instruction, QuotedText, StyleSheet and ancestors: TXmlNode TsdContainerNode TsdElement TsdDtdElement TsdDtdAttList TsdDtdEntity TsdDtdNotation TsdDocType TsdDeclaration TsdStyleSheet TsdCharData TsdQuotedText TsdProcessingInstruction TsdComment TsdCData TsdConditionalSection TsdAttribute}

 

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/shangdawei/p/3351543.html

你可能感兴趣的文章
Java中的String,StringBuilder,StringBuffer三者的区别
查看>>
JavaWeb--自定义标签4--带父标签的自定义标签
查看>>
FreeBSD 下sac101.6a编译失败解决办法
查看>>
python之list
查看>>
vs 配色方案
查看>>
大熊君说说JS与设计模式之------单例模式Singleton()
查看>>
ROC曲线【转】
查看>>
jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关...
查看>>
python字符串内建函数
查看>>
第一章 javascript简介
查看>>
CentOS6.3升级GCC到GCC4.8.2
查看>>
WebService工作原理及传输安全问题
查看>>
字符数组与字符指针的差别与联系
查看>>
将ipv4地址转换为不同格式(python程序)
查看>>
判断点是否在区域的python实现(射线法)
查看>>
奋斗的小蜗牛
查看>>
HTTP状态码以及其含义大全
查看>>
【转载】 C#中List集合使用First方法查找符合条件的第一个元素
查看>>
Java异常处理和设计
查看>>
vue学习之组件
查看>>