Jump to content

Reading XML File


 Share

Recommended Posts

Hi all.

I'm having issues reading a xml file and returning the version number <rules version="467">

Here is an example of the xml file:

<rules version="467">
  <docMode>
    <domain docMode="9">site1</domain>
    <domain docMode="9">site2</domain>
    <domain docMode="8">site3</domain>
    <domain docMode="5">site4</domain>
    <domain docMode="9">site5</domain>
    <domain docMode="9">site6</domain>
  </docMode>

I am trying to get the "<rules version="467">" number 467 but when I read the file it does not return that line.

ConsoleWrite(FileRead("C:\Test\temp.xml") & @CRLF)

console output:

<docMode>
    <domain docMode="9">site1</domain>
    <domain docMode="9">site2</domain>
    <domain docMode="8">site3</domain>
    <domain docMode="5">site4</domain>
    <domain docMode="9">site5</domain>
    <domain docMode="9">site6</domain>
  </docMode>

and is missing <rules version="467">

Link to comment
Share on other sites

  • Moderators

It works for me:

Quote

>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\LoganJ\Desktop\Test Forum Scripts.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
<rules version="467">
  <docMode>
    <domain docMode="9">site1</domain>
    <domain docMode="9">site2</domain>
    <domain docMode="8">site3</domain>
    <domain docMode="5">site4</domain>
    <domain docMode="9">site5</domain>
    <domain docMode="9">site6</domain>
  </docMode>

Are you trying to extract just the 467 number, or the whole string?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

$oXML = ObjCreate("Microsoft.XMLDOM")
$oXML.Load(@DesktopDir & "\test.xml")
$oNode = $oXML.selectSingleNode('//rules')
$sVersion = $oNode.getAttribute('version')
ConsoleWrite($sVersion & @CRLF)

return:

467

 

Only works when I made the XML valid:

<rules version="467">
   <docMode>
     <domain docMode="9">site1</domain>
     <domain docMode="9">site2</domain>
     <domain docMode="8">site3</domain>
     <domain docMode="5">site4</domain>
     <domain docMode="9">site5</domain>
     <domain docMode="9">site6</domain>
   </docMode> 
</rules>

 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...