Browse Source

* fcl-xml, making progress with streaming API, implemented a few more methods.

git-svn-id: trunk@20474 -
sergei 13 years ago
parent
commit
eabc0cb53a
2 changed files with 35 additions and 1 deletions
  1. 34 1
      packages/fcl-xml/src/xmlread.pp
  2. 1 0
      packages/fcl-xml/src/xmlreader.pp

+ 34 - 1
packages/fcl-xml/src/xmlread.pp

@@ -396,6 +396,8 @@ type
     procedure ParseAttribute(ElDef: TElementDecl);
     procedure ParseAttribute(ElDef: TElementDecl);
     function  ReadTopLevel: Boolean;
     function  ReadTopLevel: Boolean;
     procedure NextAttrValueChunk;
     procedure NextAttrValueChunk;
+    function  GetLineNumber: Integer;
+    function  GetLinePosition: Integer;
   public
   public
     function  Read: Boolean; override;
     function  Read: Boolean; override;
     function  MoveToFirstAttribute: Boolean; override;
     function  MoveToFirstAttribute: Boolean; override;
@@ -407,6 +409,9 @@ type
     function  GetAttribute(i: Integer): XMLString; override;
     function  GetAttribute(i: Integer): XMLString; override;
     function  GetAttribute(const AName: XMLString): XMLString; override;
     function  GetAttribute(const AName: XMLString): XMLString; override;
     function  GetAttribute(const ALocalName, nsuri: XMLString): XMLString; override;
     function  GetAttribute(const ALocalName, nsuri: XMLString): XMLString; override;
+    function  LookupNamespace(const APrefix: XMLString): XMLString; override;
+    property  LineNumber: Integer read GetLineNumber;
+    property  LinePosition: Integer read GetLinePosition;
   protected
   protected
     function  GetDepth: Integer; override;
     function  GetDepth: Integer; override;
     function  GetNodeType: TXmlNodeType; override;
     function  GetNodeType: TXmlNodeType; override;
@@ -1379,6 +1384,7 @@ begin
   FNesting := 0;
   FNesting := 0;
   FValidatorNesting := 0;
   FValidatorNesting := 0;
   FCurrNode := @FNodeStack[0];
   FCurrNode := @FNodeStack[0];
+  FCurrAttrIndex := -1;
   if FNamespaces then
   if FNamespaces then
   begin
   begin
     FNSHelper := TNSSupport.Create;
     FNSHelper := TNSSupport.Create;
@@ -2794,7 +2800,9 @@ end;
 
 
 function TXMLTextReader.GetAttribute(i: Integer): XMLString;
 function TXMLTextReader.GetAttribute(i: Integer): XMLString;
 begin
 begin
-  result := '';
+  if (i < 0) or (i >= FAttrCount) then
+    raise EArgumentOutOfRangeException.Create('index');
+  result := FNodeStack[FNesting+i+1].FValueStr;
 end;
 end;
 
 
 function TXMLTextReader.GetAttribute(const AName: XMLString): XMLString;
 function TXMLTextReader.GetAttribute(const AName: XMLString): XMLString;
@@ -2873,6 +2881,31 @@ begin
   result := FSource.SystemID;
   result := FSource.SystemID;
 end;
 end;
 
 
+function TXMLTextReader.GetLineNumber: Integer;
+begin
+  result := FCurrNode^.FLoc.Line;
+end;
+
+function TXMLTextReader.GetLinePosition: Integer;
+begin
+  result := FCurrNode^.FLoc.LinePos;
+end;
+
+function TXMLTextReader.LookupNamespace(const APrefix: XMLString): XMLString;
+var
+  prefixatom: PHashItem;
+  b: TBinding;
+begin
+  result := '';
+  if FNamespaces then
+  begin
+    prefixatom := FNSHelper.GetPrefix(PWideChar(APrefix),Length(APrefix));
+    b := TBinding(prefixatom^.Data);
+    if Assigned(b) then
+      result := b.Uri;
+  end;
+end;
+
 function TXMLTextReader.MoveToFirstAttribute: Boolean;
 function TXMLTextReader.MoveToFirstAttribute: Boolean;
 begin
 begin
   result := False;
   result := False;

+ 1 - 0
packages/fcl-xml/src/xmlreader.pp

@@ -72,6 +72,7 @@ type
     procedure ReadStartElement(const aLocalName, aNamespace: XMLString); overload;
     procedure ReadStartElement(const aLocalName, aNamespace: XMLString); overload;
     function ReadString: XMLString; virtual;
     function ReadString: XMLString; virtual;
     procedure Skip; virtual;
     procedure Skip; virtual;
+    function LookupNamespace(const APrefix: XMLString): XMLString; virtual; abstract;
 
 
     function GetAttribute(i: Integer): XMLString; virtual; abstract;
     function GetAttribute(i: Integer): XMLString; virtual; abstract;
     function GetAttribute(const Name: XMLString): XMLString; virtual; abstract;
     function GetAttribute(const Name: XMLString): XMLString; virtual; abstract;