AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

xml file reading and modifying

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
egon
Guest





PostPosted: Fri Nov 06, 2009 12:46 pm    Post subject: xml file reading and modifying Reply with quote

I want to modify an xml files, but I cant even get the reading of the xml file to work. I am using xpath.
The xml file looks like this:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<message xmlns:ep="http://EP" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./x_aruanne247.xsd">
   <message_header>
      <from>700</from>
      <date>2009-10-07T17:38:23</date>
      <sender>John Doe</sender>
      <send_mail>John@mail.com</send_mail>
      <send_phone>123456</send_phone>
      <comment></comment>
      <require_receipt>yes</require_receipt>
   </message_header>
   <report>
      <report_header>
         <typeid>247</typeid>
         <timeid>2009-09-30</timeid>
         <compiler>John Doe</compiler>
         <comp_mail>John@mail.com</comp_mail>
         <comp_phone>123456</comp_phone>
      </report_header>
   </report>
</message>

If I want to read the senders name the code looks like this:
Code:
#Include xpath.ahk

xmlfile = 247_30092009.xml
xml := xpath_load(xmlfile)
sender := xpath(xml, "/message/message_header/sender/text()")
MsgBox, %sender%


but all I get is an empty message box.
What I am doing wrong?
Back to top
OceanMachine



Joined: 15 Oct 2007
Posts: 139

PostPosted: Fri Nov 06, 2009 2:29 pm    Post subject: Reply with quote

I don't think you are doing anything wrong, you seem to be doing what is required in the documentation:

XPath Reference wrote:
#Include xpath.ahk ; include functions (only required if it is not in your standard library)

; parsing documents:
xml := xpath_load("books.xml") ; load an XML document
titles := xpath(xml, "/bookstore/books[price>35]/title/text()") ; get book titles with a cost greater than 35


However, when I try xpath_load with a string directly (as per the above) I get an error that a variable must be passed to this ByRef parameter.

Trying it as per your code, the variable "xml" returns false, indicating that there was perhaps a problem loading the source XML.

However, I just tried this:

Code:
#Include xpath.ahk

xmlfile = 247_30092009.xml
xpath_load(xml, xmlfile)
sender := xpath(xml, "/message/message_header/sender/text()")
MsgBox, %sender%


This seems to work, not sure why your code didn't work, as it seems to be the same as the documentation?

Maybe Titan can tell us where the problem is (although I don't know if he still supports XPath any more)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group