NativeXml: A native Delphi XML parser and writer

   2023-02-09 学习力0
核心提示:http://www.simdesign.nl/xml.htmlThis 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 "use

http://www.simdesign.nl/xml.html

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 <name {attr}> [value] [sub-elements] </name>

xeAttribute, // 1 attribute ( name='value' or name="value") : <element name='value'>....</element>
xeCharData,
// 2 character data in a node : <element>char data</element>
xeComment,
// 3 comment <!--{comment}-->
xeCData,
// 4 literal data <![CDATA[{data}]]>
xeCondSection,
// 5 conditional section <![ IGNORE / INCLUDE [ markup ]]>
xeDeclaration,
// 6 xml declaration <?xml{declaration}?>
xeStylesheet,
// 7 stylesheet <?xml-stylesheet{stylesheet}?>
xeDocType,
// 8 doctype dtd declaration <!DOCTYPE{spec}>
xeDtdElement,
// 9 dtd element <!ELEMENT >
xeDtdAttList,
// 10 dtd attlist <!ATTLIST >
xeDtdEntity,
// 11 dtd entity <!ENTITY >
xeDtdNotation,
// 12 dtd notation <!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
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

  • Delphi中的消息处理机制 delphi 方法
    每一个VCL都有一内在的消息处理机制,其基本点就是构件类接收到某些消息并把它们发送给适当的处理方法,如果没有特定的处理方法,则调用缺省的消息处理句柄。    其中mainwndproc是定义在Twincontrol类中的一个静态方法,不能被重载(Override)。它不直接处
    02-09
  • Delphi XE6 通过JavaScript API调用百度地图
    Delphi XE6 通过JavaScript API调用百度地图
    参考昨天的内容,有朋友还是问如何调用百度地图,也是,谁让咱都在国内呢,没办法,你懂的。 首先去申请个Key,然后看一下百度JavaScript的第一个例子:http://developer.baidu.com/map/jsdemo.htm下一步,就是把例子中的代码,移动TWebBrower中。 unit Unit
    02-09
  • Delphi编译/链接过程 delphi编程案例
    Delphi编译/链接过程 delphi编程案例
    下面展示了Delphi是怎样编译源文件,并且把它们链接起来,最终形成可执行文件。当Delphi编译项目(Project)时,将编译项目源文件、窗体单元和其他相关单元,在这个过程中将会发生好几件事情:首先,Object Pascal编译器把项目单元编译为二进制对象文件,然后
    02-09
  • Delphi CompilerVersion Constant / Compiler C
    http://delphi.wikia.com/wiki/CompilerVersion_Constant The CompilerVersion constant identifies the internal version number of the Delphi compiler.It is defined in the System unit and may be referenced either in code just as any other consta
    02-09
  • Delphi revelations #1 – kbmMW Smart client
    Delphi 启示 #1 – kbmMW Smart client on NextGen (Android) – 作用域问题以更高级的方式使用kbmMW smart client,在Android设备上,我遇到了问题。通过继承TInvokeableVariantType,kbmMW smart client可以使用Delphi支持的特殊类型的自定义Variant,从而可
    02-09
  • Delphi 调用DLL外部函数时的指针参数
    某项目需要调用设备厂家提供的DLL的函数,厂家给了一个VB的例子,有个参数是ByRef pBuffer As Single。于是在Delphi中用buffer:array of single代替:function func(buffer:array of single;count:integer):integer;far;stdcall;external 'func.dll';调用后bu
    02-09
  • 《zw版·Halcon-delphi系列原创教程》 Halcon分
    《zw版·Halcon-delphi系列原创教程》 Halcon分类函数012,polygon,多边形为方便阅读,在不影响说明的前提下,笔者对函数进行了简化::: 用符号“**”,替换:“procedure”:: 用大写字母“X”,替换:“IHUntypedObjectX”:: 省略了字符:“const”、“OleVa
    02-09
  • 最简单的delphi启动画面(转)
    首先做一窗体,然后将BorderStyle的属性设为bsnone,放image控件,align设为alclient 然后将主程序的修改为 uses Windows, Forms, Unit1 in 'Unit1.pas' {Form1}, Unit2 in 'Unit2.pas' {Form2}; {$ R *.res} begin Application.Initialize; Form2:=TForm2.Cre
    02-09
  • Delphi备忘三:TCollection的使用,用Stream保
     代码unit ufrmGetFunctionDefine;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,TypInfo,  Dialogs,ufrmStockBaseCalc, StdCtrls, ComCtrls,uQEFuncManager,uWnDataSet,uDataService;type  T
    02-09
  • Delphi Dcp 和BPL的解释
    dcp = delphi compiled package,是 package 编译时跟 bpl 一起产生出来的,记录着 package 中公开的 class、procedure、function、variable、const.... 等等的名称和相对位址。package英文翻译过来就是“包”。如果 某个控件包 A 引用了 控件包 B,当 控件包
    02-09
点击排行