Read an XML document with namespaces and import the data by path using DELPHI.
const
NSMY = 'http://my.namspace.com/namespace';
PATH = '/my:myFields/my:myFields_1/my:FieldName_1';
var
text: string;
Doc: DOMDocument;
node:IXMLDOMNode;
begin
Doc:=CreateComObject(CLASS_DOMDocument) AS IXMLDOMDocument2;
Doc.load('c:\testXML\testForm.xml');
Doc.setProperty('SelectionNamespaces', Format('xmlns:my="%s"', [NSMY]));
node := Doc.selectSingleNode(PATH);
Text:=node.Text;
end;
To access a node in the 'my:' namespace by xpath use the units MSXML2_TLB and ComObj.
You can create MSXML2_TLB by importing the type library for MSXMLv3.0.
Showing posts with label DELPHI. Show all posts
Showing posts with label DELPHI. Show all posts
Sunday, 18 January 2009
Wednesday, 29 August 2007
Delphi code to fetch your own public IP address
function whatismyip(): String;
var anurl: String;
var r:TregExpr;
var myip: string;
begin
anurl := IdHTTP1.Get('http:\\www.whatismyip.com');
r:= TregExpr.Create;
r.Expression := '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if r.Exec(anurl) then myip := r.Match[0];
r.Destroy;
whatismyip:=myip;
end;
This snippet requires indy and also regular expressions from http://regexpstudio.com/
There is a version using windows sockets here :-
http://www.delphifusion.com/forum/showthread.php?t=247
var anurl: String;
var r:TregExpr;
var myip: string;
begin
anurl := IdHTTP1.Get('http:\\www.whatismyip.com');
r:= TregExpr.Create;
r.Expression := '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if r.Exec(anurl) then myip := r.Match[0];
r.Destroy;
whatismyip:=myip;
end;
This snippet requires indy and also regular expressions from http://regexpstudio.com/
There is a version using windows sockets here :-
http://www.delphifusion.com/forum/showthread.php?t=247
Labels:
DELPHI,
Fetch your own IP,
IP address,
regular expressions
Subscribe to:
Posts (Atom)