Jump to content
Sign in to follow this  
antmar904

Reading XML File

Recommended Posts

antmar904

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">

Share this post


Link to post
Share on other sites
JLogan3o13

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?


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
antmar904

just the 467.  the rules version number will be manually changed everytime the xml file is edited.

Edited by antmar904

Share this post


Link to post
Share on other sites
jdelaney
$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
  • Like 1

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.

Share this post


Link to post
Share on other sites
antmar904

Thanks

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×