1. The following code does not work if I compile as Unicode
2. Does anyone have a conversion from Dot Net Ticks to Purebasic DateTime
For convenience the response is hard coded into the sample
Code: Select all
Declare.l SplitPath(Array r.s(1), text.s, separator.s = ",")
Declare.s XML_GetValue(path.s,xml.s)
Procedure.s XML_GetValue(path.s,xml.s)
result.s=""
Dim p.s(0)
If SplitPath(p(),path,"\")>0
xmlPos.i=0
If CatchXML(1,@xml,Len(xml),#PB_XML_StreamStart,#PB_UTF8)
*xmlHandle = RootXMLNode(1)
If *xmlHandle <> 0
*rootnode=ChildXMLNode(*xmlHandle)
If *rootnode <> 0
If GetXMLNodeName(*rootnode)= p(xmlPos)
xmlPos = xmlPos + 1
If xmlPos > ArraySize(p())
result = GetXMLNodeText(*rootnode)
Else
*childnode=ChildXMLNode(*rootnode)
While *childnode <> 0
If GetXMLNodeName(*childnode) = p(xmlPos)
xmlPos = xmlPos + 1
If xmlPos>ArraySize(p())
result = GetXMLNodeText(*childnode)
Break
Else
*childnode=ChildXMLNode(*childnode)
EndIf
Else
*childnode=NextXMLNode(*childnode)
EndIf
Wend
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
ProcedureReturn result
EndProcedure
Procedure.l SplitPath(Array r.s(1), text.s, separator.s = ",") ; String to Array
Protected index.l, size.l = CountString(text, separator)
ReDim r.s(size)
For index = 0 To size
r(index) = StringField(text, index + 1, separator)
Next
ProcedureReturn size
EndProcedure
testXML.s = "<s:Envelope xmlns:s="+Chr(34)+"http://schemas.xmlsoap.org/soap/envelope/"+Chr(34)+"><s:Header><ActivityId CorrelationId="+Chr(34)+"680096f1-7a4c-4c73-87ef-b82fdd4297c9"+Chr(34)+" xmlns="+Chr(34)+"http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics"+Chr(34)+">0a31f79a-80fe-43d2-8248-f989616bdd2d</ActivityId></s:Header><s:Body><DevicePingResponse xmlns="+Chr(34)+"http://tempuri.org/"+Chr(34)+"><DevicePingResult z:Id="+Chr(34)+"i1"+Chr(34)+" xmlns:a="+Chr(34)+"http://schemas.datacontract.org/2004/07/NetcardServer.Server.DataContracts"+Chr(34)+" xmlns:i="+Chr(34)+"http://www.w3.org/2001/XMLSchema-instance"+Chr(34)+" xmlns:z="+Chr(34)+"http://schemas.microsoft.com/2003/10/Serialization/"+Chr(34)+"><a:Ticks>634654947847413260</a:Ticks></DevicePingResult></DevicePingResponse></s:Body></s:Envelope>"
Ticks.s = XML_GetValue("s:Envelope\s:Body\DevicePingResponse\DevicePingResult\a:Ticks",testXML)
MessageRequester("",Ticks)