COM Interface to MSXML

Windows specific forum
User avatar
Kiffi
Addict
Addict
Posts: 1510
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

aXend wrote:The code is below. [...]
Whow! Great! Thank's a lot!

Greetings ... Kiffi
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

I can't seem to figure out why this won't work :

It crashes, and according to the OnError lib inside the Ansi2Uni(tag) procedure (the first time it's called in the getElementsByTagName method call) at the line SysFreeString_(unicodestr)

I'd like to either loop through all the tags and values in the XML doc or be able to get single tag values. This code works if I don't put it in a procedure, so it is probably something to do with passing the pointer..

Code: Select all

Procedure get_xml_tag(*oXML_update.myIXMLDOMDocument)
  
  nodetxt.s = Space(1000)
  
  tag.s = "Current_Version"
  
  Debug "In get_xml_tag"
  
  If *oXML_update\getElementsByTagName(Ansi2Uni(tag),@oNodelist.myIXMLDOMNodeList) = #S_OK

    oNodelist\get_length(@length)
    
    Debug "Length : " + Str(length)
    
    For i=0 To length-1
      
      oNodelist\get_item(i,@oNode.myIXMLDOMNode)
      
      oNode\get_nodeName(@name)
      
      oNode\get_text(@value) ;
      
      nodetxt = Uni2Ansi(name)+":"+Uni2Ansi(value)
      
      oNodelist\nextNode(@oNode.myIXMLDOMNode)
      
      Debug nodetxt
      
    Next
    
  EndIf
  
  If oNode
    
    oNode\Release()
    
  EndIf
  
  If oNodelist
    
    oNodelist\Release()
    
  EndIf   
  
EndProcedure
For reference :

Code: Select all

Procedure.l Ansi2Uni(ansistr.s)
  lenA.l = Len(ansistr)
  lenW = MultiByteToWideChar_(#CP_ACP, 0, ansistr, lenA, 0, 0)
  If (lenW > 0) ; Check whether conversion was successful
    unicodestr = SysAllocStringLen_(0, lenW)
    MultiByteToWideChar_(#CP_ACP, 0, ansistr, lenA, unicodestr, lenW)
    result = unicodestr
    SysFreeString_(unicodestr)
    ProcedureReturn result
  Else 
    ProcedureReturn 0
  EndIf
EndProcedure
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
aXend
Enthusiast
Enthusiast
Posts: 103
Joined: Tue Oct 07, 2003 1:21 pm
Location: Netherlands

Post by aXend »

With me this code works perfectly. I changed nothing except for the tag. I tested it with tag="Description" from the xml testfile I posted earlier.
So.. I don't know why it doesn't work with you. May be you should send the xml file you're testing with?
BTW: I use COMLIB now, so I coded:

Code: Select all

oXML.myIXMLDOMDocument = CreateObject("Microsoft.XMLDOM")
oXML\put_async(#False)

loadXML.VARIANT
loadXML\vt = #VT_BSTR
loadXML\bstrVal = Ansi2Uni("test_ie.xml")
*V1.pToVariant = loadXML

If oXML\load(*V1\a,*V1\b,*V1\c,*V1\d,@success.l) <> #S_OK
  XMLError()
EndIf

get_xml_tag(oXML)

If oXML
  ReleaseObject(oXML)
EndIf

End
COMLIB also contains Ansi2Uni and Uni2Ansi.
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

I'm going to convert everything to the COMLib in just a few minutes, but..

This is the XML :

Code: Select all

<Update>

	<Current_Version>1.2.13</Current_Version>

	<Message>This is a test message!</Message>

</Update>
Craaaazy.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

Doh. I was passing @oXML to the procedure. Duuuuuh.

Gotta love that kind of stuff... Thanks for all the help on this!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Post Reply