mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 15:29:25 +02:00
* fixed bug in libxml2 tree.inc
* added new xsd helper functions git-svn-id: trunk@11655 -
This commit is contained in:
parent
01dc3a0e12
commit
5eb4081bc0
@ -659,7 +659,7 @@ function xmlIsBlankNode(node: xmlNodePtr): cint; XMLCALL; XMLPUBFUN;
|
||||
function xmlDocSetRootElement(doc: xmlDocPtr; root: xmlNodePtr): xmlNodePtr; XMLCALL; XMLPUBFUN;
|
||||
{$ENDIF} (* defined(LIBXML_TREE_ENABLED) || defined(LIBXML_WRITER_ENABLED) *)
|
||||
{$IFDEF LIBXML_TREE_ENABLED}
|
||||
procedure xmlIsBlankNode(cur: xmlNodePtr; name: xmlCharPtr); XMLCALL; XMLPUBFUN;
|
||||
procedure xmlNodeSetName(cur: xmlNodePtr; name: xmlCharPtr); XMLCALL; XMLPUBFUN;
|
||||
{$ENDIF} (* LIBXML_TREE_ENABLED *)
|
||||
function xmlAddChild(parent, cur: xmlNodePtr): xmlNodePtr; XMLCALL; XMLPUBFUN;
|
||||
function xmlAddChildList(parent, cur: xmlNodePtr): xmlNodePtr; XMLCALL; XMLPUBFUN;
|
||||
|
@ -6,10 +6,13 @@ unit xmlxsd;
|
||||
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;
|
||||
@ -23,6 +26,40 @@ 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;
|
||||
@ -38,6 +75,20 @@ 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;
|
||||
@ -107,4 +158,246 @@ 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.
|
Loading…
Reference in New Issue
Block a user