⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xpxmldom.pas

📁 Delphi XML & XPATH源代码
💻 PAS
📖 第 1 页 / 共 4 页
字号:
function TXMLPDOMElement.GetElement: TXpElement;
begin
  Result := Node as TXpElement;
end;

function TXMLPDOMElement.get_tagName: DOMString;
begin
  Result := Element.TagName;
end;

function TXMLPDOMElement.getAttribute(const name: DOMString): DOMString;
begin
  Result := Element.GetAttribute(name);
end;

function TXMLPDOMElement.getAttributeNS(
  const namespaceURI, localName: DOMString): DOMString;
begin
  Result := Element.GetAttributeNS(namespaceURI, localName);
end;

function TXMLPDOMElement.getAttributeNode(const name: DOMString): IDOMAttr;
begin
  Result := MakeNode(Element.GetAttributeNode(name), FOwnerDocument) as IDOMAttr;
end;

function TXMLPDOMElement.getAttributeNodeNS(
  const namespaceURI, localName: DOMString): IDOMAttr;
begin
  Result := MakeNode(Element.Attributes.GetNamedItemNS(namespaceURI, localName),
    FOwnerDocument) as IDOMAttr;
end;

function TXMLPDOMElement.getElementsByTagName(const name: DOMString):
  IDOMNodeList;
begin
  Result := MakeNodeList(Element.GetElementsByTagName(name), FOwnerDocument);
end;

function TXMLPDOMElement.getElementsByTagNameNS(
  const namespaceURI, localName: DOMString): IDOMNodeList;
begin
  Result := MakeNodeList(Element.GetElementsByTagNameNS(namespaceURI, localName),
    FOwnerDocument);
end;

function TXMLPDOMElement.hasAttribute(const name: DOMString): WordBool;
begin
  Result := Element.HasAttribute(name);
end;

function TXMLPDOMElement.hasAttributeNS(
  const namespaceURI, localName: DOMString): WordBool;
begin
  Result := Element.GetAttributeNodeNS(namespaceURI, localName) <> nil;
end;

procedure TXMLPDOMElement.removeAttribute(const name: DOMString);
begin
  Element.RemoveAttribute(name);
end;

function TXMLPDOMElement.removeAttributeNode(const oldAttr: IDOMAttr): IDOMAttr;
begin
  Result := MakeNode(Element.RemoveAttributeNode(
    GetNode(oldAttr) as TXpAttribute), FOwnerDocument) as IDOMAttr;
end;

procedure TXMLPDOMElement.removeAttributeNS(
  const namespaceURI, localName: DOMString);
begin
  Element.RemoveAttributeNS(namespaceURI, localName);
end;

procedure TXMLPDOMElement.setAttribute(const name, value: DOMString);
begin
  Element.SetAttribute(name, value);
end;

function TXMLPDOMElement.setAttributeNode(const newAttr: IDOMAttr): IDOMAttr;
begin
  Result := MakeNode(Element.SetAttributeNode(
    GetNode(newAttr) as TXpAttribute), FOwnerDocument) as IDOMAttr;
end;

function TXMLPDOMElement.setAttributeNodeNS(const newAttr: IDOMAttr): IDOMAttr;
begin
  Result := MakeNode(Element.SetAttributeNodeNS(
    GetNode(newAttr) as TXpAttribute), FOwnerDocument) as IDOMAttr;
end;

procedure TXMLPDOMElement.setAttributeNS(
  const namespaceURI, qualifiedName, value: DOMString);
begin
  Element.SetAttributeNS(namespaceURI, qualifiedName, value);
end;

procedure TXMLPDOMElement.normalize;
begin
  Element.Normalize;
end;

{ TXMLPDOMText ----------------------------------------------------------------}

function TXMLPDOMText.splitText(offset: Integer): IDOMText;
begin
  Result := MakeNode((Node as TXpText).SplitText(offset), FOwnerDocument)
    as IDOMText;
end;

{ TXMLPDOMDocumentTypeChildren ------------------------------------------------}

type
  TXMLPDOMDocumentTypeChildren = class(TInterfacedObject, IDOMNodeList)
  private
    FDocumentType: TXMLPDOMDocumentType;
  protected
    { IDOMNodeList }
    function get_item(index: Integer): IDOMNode; safecall;
    function get_length: Integer; safecall;
  public
    constructor Create(const DocumentType: TXMLPDOMDocumentType);
  end;

constructor TXMLPDOMDocumentTypeChildren.Create(
  const DocumentType: TXMLPDOMDocumentType);
begin
  inherited Create;
  FDocumentType := DocumentType;
end;

function TXMLPDOMDocumentTypeChildren.get_item(index: Integer): IDOMNode;
var
  Index1, Index2: Integer;
begin
  Index1 := 0;
  for Index2 := 0 to FDocumentType.DocumentType.ChildNodes.Length - 1 do
    if FDocumentType.DocumentType.ChildNodes.Item(Index2).NodeType in
        [ELEMENT_NODE..NOTATION_NODE, ENTITY_DECL_NODE, NOTATION_DECL_NODE] then
    begin
      if Index1 = index then
      begin
        Result := MakeNode(FDocumentType.DocumentType.ChildNodes.Item(Index2),
          FDocumentType.FOwnerDocument);
        Exit;
      end;
      Inc(Index1);
    end;
  Result := MakeNode(FDocumentType.DocumentType.ExternalDTD,
    FDocumentType.FOwnerDocument);
end;

function TXMLPDOMDocumentTypeChildren.get_length: Integer;
var
  Index: Integer;
begin
  Result := 0;
  for Index := 0 to FDocumentType.DocumentType.ChildNodes.Length - 1 do
    if FDocumentType.DocumentType.ChildNodes.Item(Index).NodeType in
        [ELEMENT_NODE..NOTATION_NODE, ENTITY_DECL_NODE, NOTATION_DECL_NODE] then
      Inc(Result);
  if Assigned(FDocumentType.DocumentType.ExternalDTD) then
    Inc(Result);
end;

{ TXMLPDOMNamedChildren -------------------------------------------------------}

type
  TXMLPDOMNamedChildren = class(TInterfacedObject, IDOMNamedNodeMap)
  private
    FDocumentType: TXMLPDOMDocumentType;
    FNodeType: Integer;
  protected
    { IDOMNamedNodeMap }
    function get_item(index: Integer): IDOMNode; safecall;
    function get_length: Integer;
    function getNamedItem(const name: DOMString): IDOMNode; safecall;
    function setNamedItem(const arg: IDOMNode): IDOMNode; safecall;
    function removeNamedItem(const name: DOMString): IDOMNode; safecall;
    function getNamedItemNS(const namespaceURI, localName: DOMString):
      IDOMNode; safecall;    { DOM Level 2 }
    function setNamedItemNS(const arg: IDOMNode): IDOMNode; safecall;
                             { DOM Level 2 }
    function removeNamedItemNS(const namespaceURI, localName: DOMString):
      IDOMNode; safecall;    { DOM Level 2 }
  public
    constructor Create(const DocumentType: TXMLPDOMDocumentType;
      NodeType: Integer);
  end;

constructor TXMLPDOMNamedChildren.Create(
  const DocumentType: TXMLPDOMDocumentType; NodeType: Integer);
begin
  inherited Create;
  FDocumentType := DocumentType;
  FNodeType     := NodeType;
end;

function TXMLPDOMNamedChildren.get_item(index: Integer): IDOMNode;
var
  Index1, Index2: Integer;
begin
  Index1 := 0;
  for Index2 := 0 to FDocumentType.DocumentType.ChildNodes.Length - 1 do
    if FDocumentType.DocumentType.ChildNodes.Item(Index2).NodeType = FNodeType then
    begin
      if Index1 = index then
      begin
        Result := MakeNode(FDocumentType.DocumentType.ChildNodes.Item(Index2),
          FDocumentType.FOwnerDocument);
        Exit;
      end;
      Inc(Index1);
    end;
  Result := nil;
end;

function TXMLPDOMNamedChildren.get_length: Integer;
var
  Index: Integer;
begin
  Result := 0;
  for Index := 0 to FDocumentType.DocumentType.ChildNodes.Length - 1 do
    if FDocumentType.DocumentType.ChildNodes.Item(Index).NodeType = FNodeType then
      Inc(Result);
end;

function TXMLPDOMNamedChildren.getNamedItem(const name: DOMString): IDOMNode;
var
  Index: Integer;
begin
  Result := nil;
  for Index := 0 to FDocumentType.DocumentType.ChildNodes.Length - 1 do
    if (FDocumentType.DocumentType.ChildNodes.Item(Index).NodeType = FNodeType) and
        (FDocumentType.DocumentType.ChildNodes.Item(Index).NodeName = name) then
    begin
      Result := MakeNode(FDocumentType.DocumentType.ChildNodes.Item(Index),
        FDocumentType.FOwnerDocument);
      Exit;
    end;
end;

function TXMLPDOMNamedChildren.getNamedItemNS(const namespaceURI,
  localName: DOMString): IDOMNode;
var
  Index: Integer;
begin
  Result := nil;
  for Index := 0 to FDocumentType.DocumentType.ChildNodes.Length - 1 do
    if (FDocumentType.DocumentType.ChildNodes.Item(Index).NodeType = FNodeType) and
        (FDocumentType.DocumentType.ChildNodes.Item(Index).NamespaceURI = namespaceURI) and
        (FDocumentType.DocumentType.ChildNodes.Item(Index).NodeName = localName) then
    begin
      Result := MakeNode(FDocumentType.DocumentType.ChildNodes.Item(Index),
        FDocumentType.FOwnerDocument);
      Exit;
    end;
end;

function TXMLPDOMNamedChildren.removeNamedItem(const name: DOMString): IDOMNode;
begin
  DOMVendorNotSupported('removeNamedItem', SXMLPartner); { Do not localize }
end;

function TXMLPDOMNamedChildren.removeNamedItemNS(const namespaceURI,
  localName: DOMString): IDOMNode;
begin
  DOMVendorNotSupported('removeNamedItemNS', SXMLPartner); { Do not localize }
end;

function TXMLPDOMNamedChildren.setNamedItem(const arg: IDOMNode): IDOMNode;
begin
  DOMVendorNotSupported('setNamedItem', SXMLPartner); { Do not localize }
end;

function TXMLPDOMNamedChildren.setNamedItemNS(const arg: IDOMNode): IDOMNode;
begin
  DOMVendorNotSupported('setNamedItemNS', SXMLPartner); { Do not localize }
end;

{ TXMLPDOMDocumentType --------------------------------------------------------}

constructor TXMLPDOMDocumentType.Create(const Node: TXpNode;
  const Document: TXMLPDOMDocument);
begin
  inherited Create(Node, Document);
  FChildren  := TXMLPDOMDocumentTypeChildren.Create(Self);
  FEntities  := TXMLPDOMNamedChildren.Create(Self, ENTITY_DECL_NODE);
  FNotations := TXMLPDOMNamedChildren.Create(Self, NOTATION_DECL_NODE);
end;

function TXMLPDOMDocumentType.GetDocumentType: TXpDocumentType;
begin
  Result := Node as TXpDocumentType;
end;

function TXMLPDOMDocumentType.get_childNodes: IDOMNodeList;
begin
  Result := FChildren;
end;

function TXMLPDOMDocumentType.get_entities: IDOMNamedNodeMap;
begin
  Result := FEntities;
end;

function TXMLPDOMDocumentType.get_internalSubset: DOMString;
begin
  Result := DocumentType.XmlDocument;
end;

function TXMLPDOMDocumentType.get_name: DOMString;
begin
  Result := DocumentType.Name;
end;

function TXMLPDOMDocumentType.get_notations: IDOMNamedNodeMap;
begin
  Result := FNotations;
end;

function TXMLPDOMDocumentType.get_publicId: DOMString;
begin
  Result := DocumentType.PublicID;
end;

function TXMLPDOMDocumentType.get_systemId: DOMString;
begin
  Result := DocumentType.SystemID;
end;

function TXMLPDOMDocumentType.hasChildNodes: WordBool;
begin
  Result := (get_childNodes.Length > 0);
end;

{ TXMLPDOMNotation ------------------------------------------------------------}

function TXMLPDOMNotation.GetNotation: TXpDTDNotation;
begin
  Result := Node as TXpDTDNotation;
end;

function TXMLPDOMNotation.get_nodeType: DOMNodeType;
begin
  Result := NOTATION_NODE;
end;

function TXMLPDOMNotation.get_publicId: DOMString;
begin
  Result := Notation.PublicId;
end;

function TXMLPDOMNotation.get_systemId: DOMString;
begin
  Result := Notation.SystemId;
end;

{ TXMLPDOMEntity --------------------------------------------------------------}

function TXMLPDOMEntity.GetEntity: TXpDTDEntity;
begin
  Result := Node as TXpDTDEntity;
end;

function TXMLPDOMEntity.get_nodeType: DOMNodeType;
begin
  Result := ENTITY_NODE;
end;

function TXMLPDOMEntity.get_notationName: DOMString;
begin
  Result := Entity.NotationName;
end;

function TXMLPDOMEntity.get_publicId: DOMString;
begin
  Result := Entity.PublicId;
end;

function TXMLPDOMEntity.get_systemId: DOMString;
begin
  Result := Entity.SystemId;
end;

{ TXMLPDOMProcessingInstruction -----------------------------------------------}

function TXMLPDOMProcessingInstruction.GetProcessingInstruction:
  TXpProcessingInstruction;
begin
  Result := Node as TXpProcessingInstruction;
end;

function TXMLPDOMProcessingInstruction.get_data: DOMString;
begin
  Result := ProcessingInstruction.Data;
end;

function TXMLPDOMProcessingInstruction.get_target: DOMString;
begin
  Result := ProcessingInstruction.Target;
end;

procedure TXMLPDOMProcessingInstruction.set_data(const value: DOMString);
begin
  ProcessingInstruction.Data := value;
end;

{ TXMLPDOMDocument ------------------------------------------------------------}

constructor TXMLPDOMDocument.Create(const Node: TXpNode;
  const Document: TXMLPDOMDocument);
begin
  FXMLObjModel             := TXpObjModel.Create(nil);
  FXMLObjModel.RaiseErrors := False;
  if Assigned(Node) then
    inherited Create(Node, Self)
  else
    inherited Create(FXMLObjModel.Document, Self);
end;

destructor TXMLPDOMDocument.Destroy;
begin
  FXMLObjModel.Free;
  inherited Destroy;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -