Page 1 of 1

revSetXMLAttribute

Posted: Thu Dec 06, 2007 1:25 am
by selvabits
Hi , How to change the attribute of a node by using the value of another attribute of the nodes

Thanks

Posted: Thu Dec 06, 2007 1:51 am
by malte
Hi,

this should work:

local tNewValue
put revXmlAttribute(tId,"/path/to/node","attributename") into tNewValue
revSetXMLAttribute tId,"/path/to/node","otherAttribute",tNewValue

the names for the commands and functions is a bit inconsistant and takes getting used to. Best search for XML in the dictionary.

Hope that helps,

Malte

Posted: Thu Dec 06, 2007 5:05 pm
by selvabits
The problem is that i dont know how to give the nodepath
because my XML structure is like this
<EdgeType id="1" name="ReportsTo" visible="true"></EdgeType>
<EdgeType id="2" name="HasInfluenceOn" visible="true"></EdgeType>

So can you tell me how to give the nodepath if it is like this , I want to change the visible attribute based on the id

Thanks
Bye

Posted: Thu Dec 06, 2007 10:12 pm
by Twit
Does that revSetXMLAttribute method take a proper xpath in the second parameter? If so, given what malte wrote above then it should be something along the lines of:

revSetXMLAttribute tId, "//EdgeType[@id='1']", "visible", tNewValue

...but I'm a complete noob at runrev so I may be way off.

Posted: Thu Dec 06, 2007 11:57 pm
by selvabits
Thanks a lot , that works , but one more doubt

put url ("file:" & "In.xml") into myFileData
put revCreateXMLTree(myFileData, false, true, false) into tDocID
put "/Graph/EdgeTypes/EdgeType[@id='1']" into nodepath
put "false"into tnew
revSetXMLAttribute tDocID,nodepath,"visible",tnew

This way i load In.xml make the changes , how do i save it back to the .xml , this may be very trivial but i am new to runtime revolution

Thanks

Posted: Fri Dec 07, 2007 12:10 am
by malte
Hi,

you might want to look at revXmlChildNames. you can reference to a node given a number in brackets then

revXmlNodeContents(tId,"/path/to/node[1]")

If you want to write the DOM object back to the XML file you will want to look at

revXMLText(tID)

for example put
revXmlText(tid) into URL ("file:"&"path/to/file.xml")

The XML stuff in rev is quite powerful, however it requires some reading. I really suggest you make yourself a HUGE can of coffee and filter the dictionary wit XML. Quite a lot to read and play with.

All the best,

Malte

Posted: Fri Dec 07, 2007 12:33 am
by selvabits
put url ("file:" & "In.xml") into myFileData
put revCreateXMLTree(myFileData, false, true, false) into tDocID
put "/Graph/EdgeTypes/EdgeType[@id='1']" into nodepath
put revXMLNodeContents(tDocID,nodepath) into initcontents
put "false"into tnew
revSetXMLAttribute tDocID,nodepath,"visible",tnew
put revXMLNodeContents(tDocID,nodepath) into contents
put revXMLText(tDocID) into URL "file:In.xml"

This does not work , moreover when i tried to see the value of initcontents it showed xmlerr, can find element
I also tried giving
revXMLNodeContents(tDocID,"/Graph/EdgeTypes/EdgeType[1]" )
What STUPID mistake am i making

Thanks

Posted: Fri Dec 07, 2007 1:04 am
by malte
Nothing stupid I think :) It is just complex to grook the Rev commands.

First of all when creating your tree you may want to do it like this

put revCreateXMLTree(myFileData, true true, false) into tDocID

There was a bug in the docs up to 2.8.1 that will parse even faulty XML. the param there should read don't parse bad data instead of parse bad data.


Secondly to get the path to a node while referencing an attribute you can use
revXmlMatchingNode function

example: I have a field with the following contents:

<test>
<EdgeType id="1" name="ReportsTo" visible="true"></EdgeType>
<EdgeType id="2" name="HasInfluenceOn" visible="true"></EdgeType>
</test>

and a button with this code:

Code: Select all

on mouseUp pMouseBtnNo
    local tDocId
    put revCreateXmlTree(the text of fld 1,true,true,false) into tDocId
    put revXmlMatchingNode(tDocId,revXmlRootNode(tDocId),"EdgeType","id","1",1)
    revDeleteXmlTree tDocId
end mouseUp
Which puts this in the messagebox:

/test/EdgeType[1]

Hope that helps.

Malte

Posted: Fri Dec 07, 2007 1:45 am
by Twit
I'm curious about this because I'll probably want to do something similar in the future. Sorry selvabits if I'm getting in your way here, but wouldn't the following do the task of loading some XML, changing an attribute, and then saving it back again? (some variables removed for simplicity)

put url ("file:In.xml") into myFileData
put revCreateXmlTree(myFileData, true, true, false) into tDocId
revSetXmlAttribute(tDocId, "//Graph/EdgeTypes/EdgeType[@id='1']", "visible", false)
put revXmlText(tDocId) into URL "file:In.xml"
revDeleteXmlTree tDocId

I'm assuming that revCreateXmlTree does the equivalent of creating a reference to an XmlDocument, and revSetXmlAttribute works on the instance in the reference provided and takes an xpath. The only reason I could think of for that not working is if revSetXmlAttribute does not work with xpath, and so you are forced to use revXmlMatchingNode. That would be extremely annoying, as you would end up with something like:

put url ("file:In.xml") into myFileData
put revCreateXmlTree(myFileData, true, true, false) into tDocId
put revXmlMatchingNode(tDocId,revXmlRootNode(tDocId),"EdgeType","id","1",1) into tPath
revSetXmlAttribute(tDocId, tPath, "visible", false)
put revXmlText(tDocId) into URL "file:In.xml"
revDeleteXmlTree tDocId

Again, sorry selvabits if this is off track. I'll be interested to see your final outcome.

Posted: Fri Dec 07, 2007 2:17 am
by selvabits
Hello Twit and Melto

Thanks a lot for your replies

when i give this in the message box put revXmlText(22) 22 being the tDocId
I still see the change not reflected ,i.e , it still remains the same , visible has not been changed to false
revSetXMLAttribute is not working in this case
What could possibly be wrong

Thanks a lot again

Posted: Fri Dec 07, 2007 11:06 am
by malte
Hi Twit,

I can not get the @ thing to work. matching node is the way to go I am afraid.

All the best,

Malte

Posted: Fri Dec 07, 2007 5:46 pm
by selvabits
Hi

RevSetXMLAttribute doesnt work for me , it says handler cant be found
Should i include something to make it work
Sorry for the trouble
Thanks

Posted: Fri Dec 07, 2007 7:09 pm
by malte
could you please post your complete script?

All the best,

Malte

Posted: Fri Dec 07, 2007 7:10 pm
by selvabits
Thanks a lot guys it worked , but how do i find the current folders location using runtime revolution

Thanks
Bye

Posted: Mon Dec 10, 2007 1:30 pm
by Janschenkel
Check out 'the defaultFolder' in the Rev dictionary - this should give you the information you want, and you can both get and set it.
When your standalone applicaiton is opened, this will point to the folder containing the standalone.app package. On Windows, this is where the executable resides, but on MacOSX, your executable will be two levels deeper within the .app package inside ./Contents/MacOS/

Hope this helped,

Jan Schenkel.