I'm having a hard time understanding XPaths. Would someone mind helping me understand it?
Here is the xml file: (I've added hyphens for spacing)
<?xml version="1.0" encoding="utf-8"?>
<Array>
- <PropertyNameValue>
- - <Value Internal_Type="String">C:\User\Jeff\Videos</Value>
- - <Name>Folders_VideoCapturesFolder</Name>
- </PropertyNameValue>
</Array>
In this example, I need "C:\User\Jeff\Videos" to change to %PortableApps.comVideos% using a filewrite operation.
I've looked at the following articles in my attempt to get this to work properly:
https://en.wikipedia.org/wiki/XPath
https://portableapps.com/manuals/PortableApps.comLauncher/topics/xml.html
https://portableapps.com/manuals/PortableApps.comLauncher/ref/launcher.i...
And my failed attempt:
[FileWrite1]
File=%PAL:DataDir%\Settings\Settings.xml
Type=XML attribute
XPath=/Array/PropertyNameValue[@Name="Folders_VideoCapturesFolder"]
Attribute=value
Value=%PortableApps.comVideos%
If I can see what I'm doing wrong, I can learn from it and fix the others that do not work.
Thanks,
Jeff Savage ~ BetaLeaf
Try something like
/Array/PropertyNameValue[Name/text()="Folders_VideoCapturesFolder"]/Value
.Also, you'll want to write XML text, not a XML attribute.
Previously known as kAlug.
I did both of the things you mentioned and was not successful in updating the xml file. I appreciate you trying tho.
Have an awesome day!
Jeff Savage ~ BetaLeaf
Have you set?:
[Activate]
XML=true
Can you try:
[FileWrite1]
Type=XML text
File=%PAL:DataDir%\Settings\Settings.xml
XPath=/Array/PropertyNameValue/Value
Value=%PortableApps.comVideos%
Please note that the path must has already existed in the xml file.
Yes I set XML=true. Had to rebuild launcher for it to actually activate.
There are multiple values like this in my xml file, so I do not think this will work, rather it would probably corrupt my xml file if it did.
<PropertyNameValue>
- - <Value Internal_Type="String">C:\User\Jeff\Videos</Value>
- - <Name>Folders_VideoCapturesFolder</Name>
</PropertyNameValue>
<PropertyNameValue>
- - <Value Internal_Type="String">C:\User\Jeff\Pictures\Screenshots</Value>
- - <Name>Folders_ScreenCapturesFolder</Name>
</PropertyNameValue>
<PropertyNameValue>
- - <Value Internal_Type="String">C:\User\Jeff\Music</Value>
- - <Name>Folders_MusicFolder</Name>
</PropertyNameValue>
The path does exist in my xml file.
Have an awesome day!
Jeff Savage ~ BetaLeaf
In this case you must be able to indendify the (Name) part first. However as far as I know, PAL do not have such ability.
One work around method you may try is save the following in "..\App\DefaultData\settings" folder.
[Sorry for I do not know how to make it show the greater and lesser sign. I replace it with ( and )]
(?xml version="1.0" encoding="utf-8"?)
(Array)
(PropertyNameValue)
(Value Internal_Type="String")DefaultVideoCapturesFolder(/Value)
(Name>Folders_VideoCapturesFolder)
(/PropertyNameValue)
(/Array)
Then in launcher ini:
[FileWrite1]
Type=Replace
File=%PAL:DataDir%\Settings\Settings.xml
Find=DefaultVideoCapturesFolder
Replace=%PortableApps.comVideos%
[FileWrite2]
Type=Replace
File=%PAL:DataDir%\Settings\Settings.xml
Find=%PAL:LastPackagePartialDir%
Replace=%PAL:PackagePartialDir%
[FileWrite3]
Type=Replace
File=%PAL:DataDir%\Settings\Settings.xml
Find=%PAL:LastPortableAppsBaseDir%
Replace=%PAL:PortableAppsBaseDir%
[FileWrite4]
Type=Replace
File=%PAL:DataDir%\Settings\Settings.xml
Find=%PAL:LastDrive%\
Replace=%PAL:Drive%\
I've had a fair bit of experience working with XML, I think I see the problem but I'll confirm this evening for you.
Ok, I took a look at it, and since you have multiple entries in your XML file labelled the same way, what JLim said above is likely the best way to handle your situation.
I'm not looking to change the default settings, just change the already existing ones. That's why I want to understand how XPaths work but couldn't get them to work on this xml file. Sometimes when I launch the portable app, it forgets it settings and starts from default. I have no idea why it does this, but when it does, what was suggested by JLim would not work. That would only work if the Data folder didn't exist at launch.
Have an awesome day!
Jeff Savage ~ BetaLeaf
FileWrite1 would only work if Data doesn't exist, however FileWrite2-4 will work only after it exists.