From 0cb1b33ac47292ff7720925fc83c594b34a19f3f Mon Sep 17 00:00:00 2001 From: inoussa Date: Mon, 13 Aug 2012 20:40:08 +0000 Subject: [PATCH] Use "LocalName" and "NamespaceURI" to handle in-line name-space git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2488 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- wst/trunk/tests/test_suite/test_parsers.pas | 5 ++-- wst/trunk/ws_helper/locators.pas | 4 +-- wst/trunk/ws_helper/ws_helper_prog.inc | 5 ++-- wst/trunk/ws_helper/wsdl_parser.pas | 19 +++++++----- wst/trunk/wst_delphi_xml.pas | 12 ++++++++ wst/trunk/wst_fpc_xml.pas | 32 ++++++++++++++++++++- wst/trunk/wst_rtti_filter/dom_cursors.pas | 18 +++++++++++- 7 files changed, 79 insertions(+), 16 deletions(-) diff --git a/wst/trunk/tests/test_suite/test_parsers.pas b/wst/trunk/tests/test_suite/test_parsers.pas index cf1052862..911e6f826 100644 --- a/wst/trunk/tests/test_suite/test_parsers.pas +++ b/wst/trunk/tests/test_suite/test_parsers.pas @@ -17,7 +17,7 @@ interface uses Classes, SysUtils, {$IFDEF FPC} - fpcunit, testutils, testregistry, DOM, XmlRead, wst_fpc_xml, + fpcunit, testutils, testregistry, DOM, wst_fpc_xml, {$ELSE} TestFrameWork, xmldom, wst_delphi_xml, {$ENDIF} @@ -328,8 +328,7 @@ const function LoadXmlFile(const AFileName : string) : TXMLDocument; begin - Result := nil; - ReadXMLFile(Result,AFileName); + Result := ReadXMLFile(AFileName); end; { TTest_CustomXsdParser } diff --git a/wst/trunk/ws_helper/locators.pas b/wst/trunk/ws_helper/locators.pas index 112c992fc..d85822d3a 100644 --- a/wst/trunk/ws_helper/locators.pas +++ b/wst/trunk/ws_helper/locators.pas @@ -21,7 +21,7 @@ uses , xmldom, wst_delphi_xml {$ENDIF WST_DELPHI} {$IFDEF FPC} - , DOM, XMLRead + , DOM, wst_fpc_xml {$ENDIF FPC} , xsd_parser; @@ -80,7 +80,7 @@ begin locFileName := FindFileName(ADocLocation); Result := (locFileName <> ''); if Result then - ReadXMLFile(ADoc,locFileName); + ADoc := ReadXMLFile(locFileName); end; function TFileDocumentLocator.FindPath(ADocLocation : string) : string; diff --git a/wst/trunk/ws_helper/ws_helper_prog.inc b/wst/trunk/ws_helper/ws_helper_prog.inc index a02f6c4f0..d5cfda2d0 100644 --- a/wst/trunk/ws_helper/ws_helper_prog.inc +++ b/wst/trunk/ws_helper/ws_helper_prog.inc @@ -23,6 +23,7 @@ resourcestring ' -f Specify unit(s) renaming option : oldName= NewName(;oldName= NewName)* '; sCOPYRIGHT = 'ws_helper, Web Service Toolkit 0.6 Copyright (c) 2006, 2007, 2008, 2009, 2010,2011 by Inoussa OUEDRAOGO'; + type TSourceFileType = ( sftPascal, sftWSDL, sftXsd ); @@ -113,7 +114,7 @@ var prsrW : IParser; prsrCtx : IParserContext; begin - ReadXMLFile(locDoc,inFileName); + locDoc := ReadXMLFile(inFileName); {$IFNDEF WST_INTF_DOM} try {$ENDIF} @@ -137,7 +138,7 @@ var prsrCtx : IParserContext; begin prsr := nil; - ReadXMLFile(locDoc,inFileName); + locDoc := ReadXMLFile(inFileName); {$IFNDEF WST_INTF_DOM} try {$ENDIF} diff --git a/wst/trunk/ws_helper/wsdl_parser.pas b/wst/trunk/ws_helper/wsdl_parser.pas index 8f16769d9..e072b39f7 100644 --- a/wst/trunk/ws_helper/wsdl_parser.pas +++ b/wst/trunk/ws_helper/wsdl_parser.pas @@ -900,12 +900,14 @@ procedure TWsdlParser.ParsePort(ANode: TDOMNode); function FindBindingNode(const AName : WideString):TDOMNode; var crs : IObjectCursor; + s : string; begin Result := FindNamedNode(FBindingCursor,AName); if Assigned(Result) then begin crs := CreateChildrenCursor(Result,cetRttiNode); if Assigned(crs) then begin - crs := CreateCursorOn(crs,ParseFilter(CreateQualifiedNameFilterStr(s_binding,FSoapShortNames),TDOMNodeRttiExposer)); + s := Format('%s = %s and %s = %s',[s_LOCAL_NAME,QuotedStr(s_binding), s_NS_URI, QuotedStr(s_soap)]); + crs := CreateCursorOn(crs,ParseFilter(s,TDOMNodeRttiExposer)); crs.Reset(); if not crs.MoveNext() then begin Result := nil; @@ -959,12 +961,14 @@ procedure TWsdlParser.ParsePort(ANode: TDOMNode); var tmpCrs : IObjectCursor; nd : TDOMNode; + s : string; begin Result := ''; if ANode.HasChildNodes() then begin + s := Format('%s = %s and %s = %s',[s_LOCAL_NAME,QuotedStr(s_address),s_NS_URI,QuotedStr(s_soap)]); tmpCrs := CreateCursorOn( CreateChildrenCursor(ANode,cetRttiNode), - ParseFilter(CreateQualifiedNameFilterStr(s_address,FSoapShortNames),TDOMNodeRttiExposer) + ParseFilter(s,TDOMNodeRttiExposer) ); tmpCrs.Reset(); if tmpCrs.MoveNext() then begin @@ -989,7 +993,7 @@ procedure TWsdlParser.ParsePort(ANode: TDOMNode); Result := False; childrenCrs := CreateChildrenCursor(ABindingNode,cetRttiNode); if Assigned(childrenCrs) then begin - s := CreateQualifiedNameFilterStr(s_binding,FSoapShortNames); + s := Format('%s = %s and %s = %s',[s_LOCAL_NAME,QuotedStr(s_binding), s_NS_URI, QuotedStr(s_soap)]); crs := CreateCursorOn(childrenCrs,ParseFilter(s,TDOMNodeRttiExposer)); crs.Reset(); if crs.MoveNext() then begin @@ -1086,9 +1090,10 @@ var Inc(in_out_count); nd := (tmpCrs.GetCurrent() as TDOMNodeRttiExposer).InnerObject; if nd.HasChildNodes() then begin + strBuffer := Format('%s = %s and %s = %s',[s_LOCAL_NAME,QuotedStr(s_body),s_NS_URI,QuotedStr(s_soap)]); tmpSoapCrs := CreateCursorOn( CreateChildrenCursor(nd,cetRttiNode), - ParseFilter(CreateQualifiedNameFilterStr(s_body,FSoapShortNames),TDOMNodeRttiExposer) + ParseFilter(strBuffer,TDOMNodeRttiExposer) ); tmpSoapCrs.Reset(); if tmpSoapCrs.MoveNext() then begin @@ -1121,17 +1126,17 @@ var var nd : TDOMNode; tmpCrs : IObjectCursor; - //s : string; - //ws : widestring; + locStrBuffer : string; begin ws := ''; s := SymbolTable.GetExternalName(AOp); ws := s; nd := FindNamedNode(ABndngOpCurs,ws); if Assigned(nd) and nd.HasChildNodes() then begin + locStrBuffer := Format('%s = %s and %s = %s',[s_LOCAL_NAME,QuotedStr(s_operation),s_NS_URI,QuotedStr(s_soap)]); tmpCrs := CreateCursorOn( CreateChildrenCursor(nd,cetRttiNode), - ParseFilter(CreateQualifiedNameFilterStr(s_operation,FSoapShortNames),TDOMNodeRttiExposer) + ParseFilter(locStrBuffer,TDOMNodeRttiExposer) ); tmpCrs.Reset(); if tmpCrs.MoveNext() then begin diff --git a/wst/trunk/wst_delphi_xml.pas b/wst/trunk/wst_delphi_xml.pas index 9958af0f4..375a2f327 100644 --- a/wst/trunk/wst_delphi_xml.pas +++ b/wst/trunk/wst_delphi_xml.pas @@ -26,10 +26,12 @@ type function CreateDoc() : TXMLDocument ; procedure WriteXML(Element: TDOMNode; const AFileName: String);overload;{$IFDEF USE_INLINE}inline;{$ENDIF} procedure WriteXML(Element: TDOMNode; AStream: TStream); overload;{$IFDEF USE_INLINE}inline;{$ENDIF} + function ReadXMLFile(AStream : TStream) : TXMLDocument;overload; procedure WriteXMLFile(doc: TXMLDocument; const AFileName: String); overload; procedure WriteXMLFile(ADoc : TXMLDocument; AStream : TStream);overload;{$IFDEF USE_INLINE}inline;{$ENDIF} procedure ReadXMLFile(out ADoc : TXMLDocument; AStream : TStream);overload;{$IFDEF USE_INLINE}inline;{$ENDIF} procedure ReadXMLFile(out ADoc: TXMLDocument; const AFilename: String);overload; + function ReadXMLFile(const AFilename: String) : TXMLDocument;overload; function NodeToBuffer(ANode : TDOMNode):string ; function FilterList(const ALIst : IDOMNodeList; const ANodeName : DOMString):IDOMNodeList;overload;{$IFDEF USE_INLINE}inline;{$ENDIF} @@ -97,6 +99,11 @@ begin (ADoc as IDOMPersist).loadFromStream(AStream); end; +function ReadXMLFile(AStream : TStream) : TXMLDocument; +begin + ReadXMLFile(Result,AStream); +end; + procedure ReadXMLFile(out ADoc: TXMLDocument; const AFilename: String); var FileStream: TStream; @@ -110,6 +117,11 @@ begin end; end; +function ReadXMLFile(const AFilename: String) : TXMLDocument; +begin + ReadXMLFile(Result, AFilename); +end; + function GetNodeItemsCount(const ANode : TDOMNode): Integer; begin if ANode.HasChildNodes then begin diff --git a/wst/trunk/wst_fpc_xml.pas b/wst/trunk/wst_fpc_xml.pas index 8fe81ba6f..a47a89692 100644 --- a/wst/trunk/wst_fpc_xml.pas +++ b/wst/trunk/wst_fpc_xml.pas @@ -38,9 +38,12 @@ type procedure ReleaseDomNode(ADomNode : TDOMNodeList);overload;{$IFDEF USE_INLINE}inline;{$ENDIF} procedure ReleaseDomNode(ADomNode : TDOMNamedNodeMap);overload;{$IFDEF USE_INLINE}inline;{$ENDIF} function CreateDoc() : TXMLDocument ;{$IFDEF USE_INLINE}inline;{$ENDIF} + function ReadXMLFile(AFileName : string) : TXMLDocument;overload; + function ReadXMLFile(AStreeam : TStream) : TXMLDocument;overload; function FindNode(ANode : TDOMNode;const ANodeName : string) : TDOMNode;{$IFDEF USE_INLINE}inline;{$ENDIF} function NodeToBuffer(ANode : TDOMNode):string ; + resourcestring SERR_NoNodeXpathExpression = 'This XPath expression does not correspond to node(s) : %s.'; @@ -48,7 +51,34 @@ resourcestring implementation uses - XMLWrite, xpath; + XMLWrite, XMLRead, xpath; + +function ReadXMLFile(AStreeam : TStream) : TXMLDocument; +begin + ReadXMLFile(Result,AStreeam); +end; + +function ReadXMLFile(AFileName : string) : TXMLDocument; +var + p : TDOMParser; + s : TXMLInputSource; + st : TMemoryStream; +begin + s := nil; + p := nil; + st := TMemoryStream.Create(); + try + st.LoadFromFile(AFileName); + s := TXMLInputSource.Create(st); + p := TDOMParser.Create(); + p.Options.Namespaces := True; + p.Parse(s,Result); + finally + p.Free(); + s.Free(); + st.Free(); + end; +end; function GetNodeItemsCount(const ANode : TDOMNode): Integer; var diff --git a/wst/trunk/wst_rtti_filter/dom_cursors.pas b/wst/trunk/wst_rtti_filter/dom_cursors.pas index 7996a2c24..fd09a724f 100644 --- a/wst/trunk/wst_rtti_filter/dom_cursors.pas +++ b/wst/trunk/wst_rtti_filter/dom_cursors.pas @@ -30,8 +30,10 @@ uses const - s_NODE_NAME = 'NodeName'; + s_LOCAL_NAME = 'LocalName'; + s_NODE_NAME = 'NodeName'; s_NODE_VALUE = 'NodeValue'; + s_NS_URI = 'NamespaceURI'; type @@ -93,6 +95,8 @@ type TDOMNodeRttiExposer = class(TPersistent) private FInnerObject: TDOMNode; + function GetLocalName : DOMString; + function GetNamespaceURI : DOMString; function GetNodeName: DOMString; function GetNodeValue: DOMString; procedure SetInnerObject(const AValue: TDOMNode); @@ -102,6 +106,8 @@ type published property NodeName: DOMString read GetNodeName; property NodeValue: DOMString read GetNodeValue; + property LocalName : DOMString read GetLocalName; + property NamespaceURI : DOMString read GetNamespaceURI; end; { TDOMNodeRttiExposerCursor } @@ -255,6 +261,16 @@ begin Result := InnerObject.NodeName; end; +function TDOMNodeRttiExposer.GetLocalName : DOMString; +begin + Result := InnerObject.LocalName; +end; + +function TDOMNodeRttiExposer.GetNamespaceURI : DOMString; +begin + Result := InnerObject.NamespaceURI; +end; + function TDOMNodeRttiExposer.GetNodeValue: DOMString; begin Result := InnerObject.NodeValue;