revSetXMLAttribute
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
revSetXMLAttribute
Hi , How to change the attribute of a node by using the value of another attribute of the nodes
Thanks
Thanks
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
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
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
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
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
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
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
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
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
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
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:
Which puts this in the messagebox:
/test/EdgeType[1]
Hope that helps.
Malte
![Smile :)](./images/smilies/icon_smile.gif)
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
/test/EdgeType[1]
Hope that helps.
Malte
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.
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.
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
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
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Location: Aalst, Belgium
- Contact:
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.
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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com