You are here

Having trouble understanding XPaths. Please advise.

10 posts / 0 new
Last post
Jeff Savage
Offline
Last seen: 6 years 1 month ago
Joined: 2014-10-05 03:44
Having trouble understanding XPaths. Please advise.

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

Aluísio A. S. G.
Offline
Last seen: 8 years 5 months ago
DeveloperTranslator
Joined: 2010-11-09 17:43
Try something like /Array

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.

Jeff Savage
Offline
Last seen: 6 years 1 month ago
Joined: 2014-10-05 03:44
Didn't work

I did both of the things you mentioned and was not successful in updating the xml file. I appreciate you trying tho. Biggrin

Have an awesome day! Biggrin
Jeff Savage ~ BetaLeaf

JLim
Offline
Last seen: 7 months 2 weeks ago
Joined: 2013-07-17 01:30
Have you set?:

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.

Jeff Savage
Offline
Last seen: 6 years 1 month ago
Joined: 2014-10-05 03:44
I have

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! Biggrin
Jeff Savage ~ BetaLeaf

JLim
Offline
Last seen: 7 months 2 weeks ago
Joined: 2013-07-17 01:30
In this case you must be able

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%\

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 1 day 20 hours ago
DeveloperModerator
Joined: 2008-07-24 18:46
Look tonight

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.

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 1 day 20 hours ago
DeveloperModerator
Joined: 2008-07-24 18:46
Ok

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.

Jeff Savage
Offline
Last seen: 6 years 1 month ago
Joined: 2014-10-05 03:44
I'm not looking to change the

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! Biggrin
Jeff Savage ~ BetaLeaf

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 1 day 20 hours ago
DeveloperModerator
Joined: 2008-07-24 18:46
Close

FileWrite1 would only work if Data doesn't exist, however FileWrite2-4 will work only after it exists.

Log in or register to post comments