123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- unit xmlxsd;
- {$mode objfpc}
- {$H+}
- interface
- uses
- libxml2,
- SysUtils;
- { Format functions }
- function xsdFormatBoolean(Value: Boolean): String;
- function xsdFormatDate(Year, Month, Day: Longword): String;
- function xsdFormatTime(Daytime: Longword): String;
- function xsdFormatDateTime(Year, Month, Day, Daytime: Longword): String;
- function xsdFormatDecimal(Value: Extended; Precision: Integer = 4; Digits: Integer = 1): String;
- function xsdFormatDouble(Value: Double): String;
- function xsdFormatFloat(Value: Single): String;
- function xsdFormatByte(Value: Shortint): String;
- function xsdFormatShort(Value: Smallint): String;
- function xsdFormatInt(Value: Longint): String;
- function xsdFormatLong(Value: Int64): String;
- function xsdFormatUnsignedByte(Value: Byte): String;
- function xsdFormatUnsignedShort(Value: Word): String;
- function xsdFormatUnsignedInt(Value: Longword): String;
- function xsdFormatUnsignedLong(Value: QWord): String;
- { Node creation functions }
- function xsdNewChildBoolean(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Boolean): xmlNodePtr;
- function xsdNewChildDate(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Year, Month, Day: Longword): xmlNodePtr;
- function xsdNewChildTime(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Daytime: Longword): xmlNodePtr;
- function xsdNewChildDateTime(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Year, Month, Day, Daytime: Longword): xmlNodePtr;
- function xsdNewChildDecimal(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Extended; Precision: Integer = 4; Digits: Integer = 1): xmlNodePtr;
- function xsdNewChildDouble(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Double): xmlNodePtr;
- function xsdNewChildFloat(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Single): xmlNodePtr;
- function xsdNewChildByte(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Shortint): xmlNodePtr;
- function xsdNewChildShort(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Smallint): xmlNodePtr;
- function xsdNewChildInt(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Longint): xmlNodePtr;
- function xsdNewChildLong(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Int64): xmlNodePtr;
- function xsdNewChildUnsignedByte(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Byte): xmlNodePtr;
- function xsdNewChildUnsignedShort(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Word): xmlNodePtr;
- function xsdNewChildUnsignedInt(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Longword): xmlNodePtr;
- function xsdNewChildUnsignedLong(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: QWord): xmlNodePtr;
- { Property creation functions }
- function xsdNewPropBoolean(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Boolean): xmlAttrPtr;
- function xsdNewPropDate(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Year, Month, Day: Longword): xmlAttrPtr;
- function xsdNewPropTime(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Daytime: Longword): xmlAttrPtr;
- function xsdNewPropDateTime(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Year, Month, Day, Daytime: Longword): xmlAttrPtr;
- function xsdNewPropDecimal(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Extended; Precision: Integer = 4; Digits: Integer = 1): xmlAttrPtr;
- function xsdNewPropDouble(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Double): xmlAttrPtr;
- function xsdNewPropFloat(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Single): xmlAttrPtr;
- function xsdNewPropByte(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Shortint): xmlAttrPtr;
- function xsdNewPropShort(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Smallint): xmlAttrPtr;
- function xsdNewPropInt(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Longint): xmlAttrPtr;
- function xsdNewPropLong(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Int64): xmlAttrPtr;
- function xsdNewPropUnsignedByte(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Byte): xmlAttrPtr;
- function xsdNewPropUnsignedShort(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Word): xmlAttrPtr;
- function xsdNewPropUnsignedInt(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Longword): xmlAttrPtr;
- function xsdNewPropUnsignedLong(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: QWord): xmlAttrPtr;
- implementation
- function xsdFormatBoolean(Value: Boolean): String;
- begin
- if Value then
- Result := 'true'
- else
- Result := 'false';
- end;
- function xsdFormatDate(Year, Month, Day: Longword): String;
- begin
- Result := Format('%4.4d-%2.2d-%2.2dZ', [Year, Month, Day]);
- end;
- function xsdFormatTime(Daytime: Longword): String;
- var
- Hour, Minute, Second: Longword;
- begin
- Daytime := Daytime div 1000; // ms to sec
- Second := Daytime mod 60; // extract sec
- Daytime := Daytime div 60; // sec to min
- Minute := Daytime mod 60; // extract min
- Daytime := Daytime div 60; // min to hour
- Hour := Daytime mod 60; // extract hour
- Result := Format('%2.2d:%2.2d:%2.2dZ', [Hour, Minute, Second]);
- end;
- function xsdFormatDateTime(Year, Month, Day, Daytime: Longword): String;
- var
- Hour, Minute, Second: Longword;
- begin
- Daytime := Daytime div 1000; // ms to sec
- Second := Daytime mod 60; // extract sec
- Daytime := Daytime div 60; // sec to min
- Minute := Daytime mod 60; // extract min
- Daytime := Daytime div 60; // min to hour
- Hour := Daytime mod 60; // extract hour
- Result := Format('%4.4d-%2.2d-%2.2dT%2.2d:%2.2d:%2.2dZ', [Year, Month, Day, Hour, Minute, Second]);
- end;
- function xsdFormatDecimal(Value: Extended; Precision: Integer; Digits: Integer): String;
- begin
- Result := FloatToStrF(Value, ffFixed, Precision, Digits);
- end;
- function xsdFormatDouble(Value: Double): String;
- begin
- Result := FloatToStr(Value);
- end;
- function xsdFormatFloat(Value: Single): String;
- begin
- Result := FloatToStr(Value);
- end;
- function xsdFormatByte(Value: Shortint): String;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatShort(Value: Smallint): String;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatInt(Value: Integer): String;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatLong(Value: Int64): String;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatUnsignedByte(Value: Byte): String;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatUnsignedShort(Value: Word): String;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatUnsignedInt(Value: Longword): String;
- begin
- Result := IntToStr(Value);
- end;
- function xsdFormatUnsignedLong(Value: QWord): String;
- begin
- Result := IntToStr(Value);
- end;
- function xsdNewChildBoolean(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Boolean): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatBoolean(Value);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildTime(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Daytime: Longword): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatTime(Daytime);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildDate(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Year, Month, Day: Longword): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatDate(Year, Month, Day);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildDateTime(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Year, Month, Day, Daytime: Longword): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatDateTime(Year, Month, Day, Daytime);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildDecimal(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Extended; Precision: Integer; Digits: Integer): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatDecimal(Value, Precision, Digits);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildDouble(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Double): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatDouble(Value);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildFloat(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Single): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatFloat(Value);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildByte(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Shortint): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatByte(Value);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildShort(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Smallint): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatShort(Value);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildInt(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Longint): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatInt(Value);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildLong(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Int64): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatLong(Value);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildUnsignedByte(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Byte): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatUnsignedByte(Value);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildUnsignedShort(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Word): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatUnsignedShort(Value);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildUnsignedInt(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Longword): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatUnsignedInt(Value);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewChildUnsignedLong(parent: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: QWord): xmlNodePtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatUnsignedLong(Value);
- Result := xmlNewChild(parent, ns, name, PChar(Tmp));
- end;
- function xsdNewPropBoolean(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Boolean): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatBoolean(Value);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropTime(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Daytime: Longword): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatTime(Daytime);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropDate(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Year, Month, Day: Longword): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatDate(Year, Month, Day);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropDateTime(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Year, Month, Day, Daytime: Longword): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatDateTime(Year, Month, Day, Daytime);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropDecimal(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Extended; Precision: Integer; Digits: Integer): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatDecimal(Value, Precision, Digits);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropDouble(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Double): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatDouble(Value);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropFloat(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Single): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatFloat(Value);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropByte(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Shortint): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatByte(Value);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropShort(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Smallint): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatShort(Value);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropInt(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Longint): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatInt(Value);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropLong(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Int64): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatLong(Value);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropUnsignedByte(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Byte): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatUnsignedByte(Value);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropUnsignedShort(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Word): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatUnsignedShort(Value);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropUnsignedInt(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: Longword): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatUnsignedInt(Value);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- function xsdNewPropUnsignedLong(node: xmlNodePtr; ns: xmlNsPtr; name: xmlCharPtr; Value: QWord): xmlAttrPtr;
- var
- Tmp: String;
- begin
- Tmp := xsdFormatUnsignedLong(Value);
- Result := xmlNewNsProp(node, ns, name, PChar(Tmp));
- end;
- end.
|