📄 xpxmldom.pas
字号:
function MakeNodeList(const NodeList: TXpNodeList;
const Document: TXMLPDOMDocument): IDOMNodeList;
begin
Result := TXMLPDOMNodeList.Create(NodeList, Document);
end;
function MakeNamedNodeMap(const NamedNodeMap: TXpNamedNodeMap;
const Document: TXMLPDOMDocument): IDOMNamedNodeMap;
begin
Result := TXMLPDOMNamedNodeMap.Create(NamedNodeMap, Document);
end;
function GetNode(const Node: IDOMNode): TXpNode;
begin
if not Assigned(Node) then
raise DOMException.Create(SNodeExpected);
Result := (Node as IXpNodeRef).GetXMLDOMNode;
end;
{ TXMLPDOMImplementation ------------------------------------------------------}
constructor TXMLPDOMImplementation.Create(
DOMImplementation: TXpDomImplementation);
begin
inherited Create;
FDOMImpl := DOMImplementation;
end;
destructor TXMLPDOMImplementation.Destroy;
begin
FDOMImpl.Free;
inherited Destroy;
end;
function TXMLPDOMImplementation.createDocument(const namespaceURI,
qualifiedName: DOMString; doctype: IDOMDocumentType): IDOMDocument;
var
DocumentType: TXpDocumentType;
Document: TXMLPDOMDocument;
begin
if Assigned(doctype) then
DocumentType := GetNode(docType) as TXpDocumentType
else
DocumentType := nil;
Document := TXMLPDOMDocument.Create(FDOMImpl.CreateDocument(
namespaceURI, qualifiedName, DocumentType), nil);
Document.FOwnerDocument := Document;
Result := Document;
end;
function TXMLPDOMImplementation.createDocumentType(const qualifiedName,
publicId, systemId: DOMString): IDOMDocumentType;
begin
Result := TXMLPDOMDocumentType.Create(FDOMImpl.CreateDocumentType(
qualifiedName, publicId, systemId), nil);
end;
function TXMLPDOMImplementation.hasFeature(
const feature, version: DOMString): WordBool;
begin
Result := DOMImpl.hasFeature(feature, version);
end;
{ TXMLPDOMNode ----------------------------------------------------------------}
constructor TXMLPDOMNode.Create(const Node: TXpNode;
const Document: TXMLPDOMDocument);
begin
Assert(Assigned(Node));
FNode := Node;
FOwnerDocument := Document;
inherited Create;
end;
function TXMLPDOMNode.appendChild(const newChild: IDOMNode): IDOMNode;
begin
Node.appendChild(GetNode(newChild));
Result := newChild
end;
function TXMLPDOMNode.cloneNode(Deep: WordBool): IDOMNode;
begin
Result := MakeNode(Node.CloneNode(deep), FOwnerDocument);
end;
function TXMLPDOMNode.get_attributes: IDOMNamedNodeMap;
begin
if not Assigned(FAttributes) and Assigned(Node.Attributes) then
FAttributes := MakeNamedNodeMap(Node.Attributes, FOwnerDocument);
Result := FAttributes;
end;
function TXMLPDOMNode.get_childNodes: IDOMNodeList;
begin
if not Assigned(FChildNodes) then
FChildNodes := MakeNodeList(Node.ChildNodes, FOwnerDocument);
Result := FChildNodes;
end;
function TXMLPDOMNode.get_firstChild: IDOMNode;
begin
Result := MakeNode(Node.FirstChild, FOwnerDocument);
end;
function TXMLPDOMNode.get_lastChild: IDOMNode;
begin
Result := MakeNode(Node.LastChild, FOwnerDocument);
end;
function TXMLPDOMNode.get_localName: DOMString;
begin
Result := Node.LocalName;
end;
function TXMLPDOMNode.get_namespaceURI: DOMString;
begin
Result := Node.NamespaceURI;
end;
function TXMLPDOMNode.get_nextSibling: IDOMNode;
begin
Result := MakeNode(Node.NextSibling, FOwnerDocument);
end;
function TXMLPDOMNode.get_nodeName: DOMString;
begin
Result := Node.NodeName;
end;
function TXMLPDOMNode.get_nodeType: DOMNodeType;
begin
Result := Node.NodeType;
end;
function TXMLPDOMNode.get_nodeValue: DOMString;
begin
Result := Node.NodeValue;
end;
function TXMLPDOMNode.get_ownerDocument: IDOMDocument;
begin
Result := FOwnerDocument;
end;
function TXMLPDOMNode.get_parentNode: IDOMNode;
begin
Result := MakeNode(Node.ParentNode, FOwnerDocument);
end;
function TXMLPDOMNode.get_prefix: DOMString;
begin
Result := Node.Prefix;
end;
function TXMLPDOMNode.get_previousSibling: IDOMNode;
begin
Result := MakeNode(Node.PreviousSibling, FOwnerDocument);
end;
function TXMLPDOMNode.hasChildNodes: WordBool;
begin
Result := Node.HasChildNodes;
end;
function TXMLPDOMNode.insertBefore(const newChild, refChild: IDOMNode): IDOMNode;
begin
Node.InsertBefore(GetNode(newChild), GetNode(refChild));
Result := newChild;
end;
procedure TXMLPDOMNode.normalize;
begin
Node.Normalize;
end;
function TXMLPDOMNode.removeChild(const childNode: IDOMNode): IDOMNode;
begin
Result := MakeNode(Node.RemoveChild(GetNode(childNode)), FOwnerDocument);
end;
function TXMLPDOMNode.replaceChild(const newChild, oldChild: IDOMNode): IDOMNode;
begin
Result := MakeNode(Node.ReplaceChild(GetNode(newChild), GetNode(oldChild)),
FOwnerDocument);
end;
procedure TXMLPDOMNode.set_nodeValue(value: DOMString);
begin
Node.NodeValue := value;
end;
function TXMLPDOMNode.supports(const feature, version: DOMString): WordBool;
begin
Result := Node.IsSupported(feature, version);
end;
function TXMLPDOMNode.GetXMLDOMNode: TXpNode;
begin
Result := Node;
end;
function TXMLPDOMNode.selectNode(const nodePath: WideString): IDOMNode;
begin
Result := MakeNode(Node.SelectSingleNode(nodePath), FOwnerDocument);
end;
function TXMLPDOMNode.selectNodes(const nodePath: WideString): IDOMNodeList;
begin
Result := MakeNodeList(Node.SelectNodes(nodePath), FOwnerDocument);
end;
{ IDOMNodeEx Interface }
function TXMLPDOMNode.get_text: DOMString;
begin
Result := Node.Text;
end;
procedure TXMLPDOMNode.set_text(const Value: DOMString);
var
Index: Integer;
begin
for Index := Node.ChildNodes.Length - 1 downto 0 do
Node.RemoveChild(Node.ChildNodes.Item(0));
Node.AppendChild(Node.OwnerDocument.CreateTextNode(Value));
end;
function TXMLPDOMNode.get_xml: DOMString;
begin
Result := Node.XmlDocument;
end;
procedure TXMLPDOMNode.transformNode(const stylesheet: IDOMNode;
var output: WideString);
var
XSLProc: TXpXSLProcessor;
begin
XSLProc := TXpXSLProcessor.Create(nil);
with XSLProc do
try
Filter := TXpFilterXML.Create(XSLProc);
XmlObjModel := FOwnerDocument.FXMLObjModel;
StyleData := GetNode(stylesheet).XmlDocument;
if ApplyStyle then
output := TXpFilterXML(Filter).XMLDocument
else
raise DOMException.Create(Errors.Text);
finally
Free;
end;
end;
procedure TXMLPDOMNode.transformNode(const stylesheet: IDOMNode;
const output: IDOMDocument);
var
XSLOutput: WideString;
XMLObjModel: TXpObjModel;
begin
transformNode(stylesheet, XSLOutput);
XMLObjModel := TXpObjModel.Create(nil);
with XMLObjModel do
try
LoadMemory(XSLOutput, Length(XSLOutput));
output.importNode(MakeNode(Document, FOwnerDocument), True);
finally
Free;
end;
end;
{ TXMLPDOMNodeList ------------------------------------------------------------}
constructor TXMLPDOMNodeList.Create(const NodeList: TXpNodeList;
const Document: TXMLPDOMDocument);
begin
inherited Create;
FNodeList := NodeList;
FOwnerDocument := Document;
end;
function TXMLPDOMNodeList.get_item(index: Integer): IDOMNode;
begin
Result := MakeNode(NodeList.Item(index), FOwnerDocument);
end;
function TXMLPDOMNodeList.get_length: Integer;
begin
Result := NodeList.Length;
end;
{ TXMLPDOMNamedNodeMap --------------------------------------------------------}
constructor TXMLPDOMNamedNodeMap.Create(const NamedNodeMap: TXpNamedNodeMap;
const Document: TXMLPDOMDocument);
begin
inherited Create;
FNamedNodeMap := NamedNodeMap;
FOwnerDocument := Document;
end;
function TXMLPDOMNamedNodeMap.get_item(index: Integer): IDOMNode;
begin
Result := MakeNode(NamedNodeMap.Item(index), FOwnerDocument);
end;
function TXMLPDOMNamedNodeMap.get_length: Integer;
begin
Result := NamedNodeMap.Length;
end;
function TXMLPDOMNamedNodeMap.getNamedItem(const name: DOMString): IDOMNode;
begin
Result := MakeNode(NamedNodeMap.GetNamedItem(name), FOwnerDocument);
end;
function TXMLPDOMNamedNodeMap.getNamedItemNS(
const namespaceURI, localName: DOMString): IDOMNode;
begin
Result := MakeNode(NamedNodeMap.GetNamedItemNS(namespaceURI, localName),
FOwnerDocument);
end;
function TXMLPDOMNamedNodeMap.removeNamedItem(const name: DOMString): IDOMNode;
begin
Result := MakeNode(NamedNodeMap.RemoveNamedItem(name), FOwnerDocument);
end;
function TXMLPDOMNamedNodeMap.removeNamedItemNS(
const namespaceURI, localName: DOMString): IDOMNode;
begin
Result := MakeNode(NamedNodeMap.RemoveNamedItemNS(namespaceURI, localName),
FOwnerDocument);
end;
function TXMLPDOMNamedNodeMap.setNamedItem(const newItem: IDOMNode): IDOMNode;
begin
Result := MakeNode(NamedNodeMap.SetNamedItem(GetNode(newItem)),
FOwnerDocument);
end;
function TXMLPDOMNamedNodeMap.setNamedItemNS(const arg: IDOMNode): IDOMNode;
begin
Result := MakeNode(NamedNodeMap.SetNamedItem(GetNode(arg)), FOwnerDocument);
end;
{ TXMLPDOMCharacterData -------------------------------------------------------}
function TXMLPDOMCharacterData.GetCharacterData: TXpCharacterData;
begin
Result := Node as TXpCharacterData;
end;
procedure TXMLPDOMCharacterData.appendData(const data: DOMString);
begin
CharacterData.AppendData(data);
end;
procedure TXMLPDOMCharacterData.deleteData(offset, count: Integer);
begin
CharacterData.DeleteData(offset, count);
end;
function TXMLPDOMCharacterData.get_data: DOMString;
begin
Result := CharacterData.Data;
end;
function TXMLPDOMCharacterData.get_length: Integer;
begin
Result := CharacterData.Length;
end;
procedure TXMLPDOMCharacterData.insertData(offset: Integer;
const data: DOMString);
begin
CharacterData.InsertData(offset, data);
end;
procedure TXMLPDOMCharacterData.replaceData(offset, count: Integer;
const data: DOMString);
begin
CharacterData.ReplaceData(offset, count, data);
end;
procedure TXMLPDOMCharacterData.set_data(const data: DOMString);
begin
CharacterData.Data := data;
end;
function TXMLPDOMCharacterData.substringData(offset, count: Integer): DOMString;
begin
Result := CharacterData.SubStringData(offset, count);
end;
{ TXMLPDOMAttr ----------------------------------------------------------------}
function TXMLPDOMAttr.GetAttribute: TXpAttribute;
begin
Result := Node as TXpAttribute;
end;
function TXMLPDOMAttr.get_name: DOMString;
begin
Result := Attribute.Name;
end;
function TXMLPDOMAttr.get_ownerElement: IDOMElement;
begin
Result := MakeNode(Attribute.OwnerElement, FOwnerDocument) as IDOMElement;
end;
function TXMLPDOMAttr.get_specified: WordBool;
begin
Result := Attribute.Specified;
end;
function TXMLPDOMAttr.get_value: DOMString;
begin
Result := Attribute.Value;
end;
procedure TXMLPDOMAttr.set_value(const attributeValue: DOMString);
begin
Attribute.Value := attributeValue;
end;
{ TXMLPDOMElement -------------------------------------------------------------}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -