Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Opening xml files

$
0
0

I need some help with opening xml files. The script I am writing has to get data from a couple of attributes in the xml files, currently my problem is that I receive two types of xml.
I do not know which type of xml I am receiving, and on opening the xml, if it is one of the types (version = 3.2) I can read it ok, but I don't seem to be able to open the other version to extract the data I need.
I am using _XMLDomWrapper, so far this is the code:

AutoIt         
  1. Global $objDoc = 0
  2. #include <_XMLDomWrapper.au3>
  3.  
  4.  
  5. $sXMLFile = "B22.xml"
  6.  
  7. ConsoleWrite("Opening " & $sXMLFile & "..." )
  8.  
  9. $result = _XMLFileOpen($sXMLFile, 'xmlns:cfdi="http://www.sat.gob.mx/cfd/3"')
  10. ConsoleWrite( "$result = " & $result & "...")
  11.  
  12. If $result = -1 Then
  13. ConsoleWrite("Error opening xml file" & $sXMLFile & @CR)
  14.     Exit
  15.  
  16. $version = _XMLGetAttrib("/cfdi:Comprobante", "version")
  17. ConsoleWrite("Version " & $version & " Error: " & @error & @CR)
  18.  
  19. If $version = "3.2" Then
  20. $rfc = _XMLGetAttrib("/cfdi:Comprobante/cfdi:Emisor", "rfc")
  21. $raz = _XMLGetAttrib("/cfdi:Comprobante/cfdi:Emisor", "nombre")
  22.  
  23.  
  24. $objDoc = 0
  25. ConsoleWrite( @CR & "File is 2.2, opening: " & $sXMLFile & "..." & @CR )
  26.  
  27.  
  28. $result = _XMLFileOpen($sXMLFile, 'xmlns="http://www.sat.gob.mx/cfd/2"')
  29. ConsoleWrite( "$result = " & $result & "...")
  30.  
  31.  
  32. $version = _XMLGetAttrib("/Comprobante", "version")
  33. ConsoleWrite("Version " & $version & " Error: " & @error & @CR)
  34.  
  35.  
  36. If $result = -1 Then
  37. ConsoleWrite("Error opening xml file" & $sXMLFile & @CR)
  38.  
  39.  
  40. $rfc = _XMLGetAttrib("/Comprobante/Emisor", "rfc")
  41. $raz = _XMLGetAttrib("/Comprobante/Emisor", "nombre")
  42.  
  43.  
  44. ConsoleWrite("RFC: " & $rfc & "  Nombre: " & $raz & @CR )

 When I use it with file A32.xml it correctly displays the data, but when using file B22.xml I only get "-1" 
 
Thanks in advance for your help

Attached Files

  • Attached File  A32.xml   4.21KB   4 downloads
  • Attached File  B22.xml   4.03KB   6 downloads

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>