It is currently December 10th, 2018, 6:36 pm

Reading xml-data

Get help with installing and using Rainmeter.
Den Duze
Posts: 12
Joined: September 14th, 2018, 9:13 am

Reading xml-data

Den Duze » September 14th, 2018, 9:53 am

Hi,

How can I read the value of a simpel xml-file into a meter?
The xml looks like the following
<?xml version="1.0"?><ttID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><ttIDRow><NMid>Test 1</NMid><INid>This is the first test</INid><ttIDRow><NMid>Test 2</NMid><INid>This is the second test</INid></ttIDRow></ttID>

Now I want the value from the INid-node back into a meter.
So I can use some regEx to find the corresponding NMid but how do i get the value of the INid returned to some meter?

Regards
Didier
User avatar
balala
Rainmeter Sage
Posts: 7151
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Reading xml-data

balala » September 14th, 2018, 11:12 am

Den Duze wrote:Hi,

How can I read the value of a simpel xml-file into a meter?
The xml looks like the following
<?xml version="1.0"?><ttID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><ttIDRow><NMid>Test 1</NMid><INid>This is the first test</INid><ttIDRow><NMid>Test 2</NMid><INid>This is the second test</INid></ttIDRow></ttID>

Now I want the value from the INid-node back into a meter.
So I can use some regEx to find the corresponding NMid but how do i get the value of the INid returned to some meter?

Regards
Didier
Using WebParser measures:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureParent]
Measure=WebParser
UpdateRate=900
Url=ADD-HERE-THE-APPROPRIATE-URL
RegExp=(?siU)<\?xml version="1.0"\?><ttID xmlns:xsi=".*"><ttIDRow><NMid>(.*)</NMid><INid>(.*)</INid><ttIDRow><NMid>(.*)</NMid><INid>(.*)</INid></ttIDRow></ttID>

[MeasureChildTest1]
Measure=WebParser
Url=[MeasureParent]
StringIndex=1

[MeasureChild1]
Measure=WebParser
Url=[MeasureParent]
StringIndex=2

[MeasureChildTest2]
Measure=WebParser
Url=[MeasureParent]
StringIndex=3

[MeasureChild2]
Measure=WebParser
Url=[MeasureParent]
StringIndex=4

[Meter]
Meter=STRING
MeasureName=MeasureChildTest1
MeasureName2=MeasureChild1
MeasureName3=MeasureChildTest2
MeasureName4=MeasureChild2
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=1. %1#CRLF#%2#CRLF#2. %3#CRLF#%4
Don't forget to add the appropriate address to the URL option of the [MeasureParent] measure.
[MeasureParent] is the parent WebParser measure, while [MeasureChildTest1] and [MeasureChild1], respectively [MeasureChildTest2] and [MeasureChild2] are the child measures. You probably will need the values returned by the [MeasureChild1] and [MeasureChild2] measures. In the [Meter] String meter I put all four, but if you don't need all of them, you can simply remove the unneeded measures (the appropriate MeasureNameXX options) and rewrite the Text option of the same meter.
Den Duze
Posts: 12
Joined: September 14th, 2018, 9:13 am

Re: Reading xml-data

Den Duze » September 18th, 2018, 9:30 am

Hi Balala,

I will try with this but I already have 1 question:
I see that you use the following Regexp:
RegExp=(?siU)<\?xml version="1.0"\?><ttID xmlns:xsi=".*"><ttIDRow><NMid>(.*)</NMid><INid>(.*)</INid><ttIDRow><NMid>(.*)</NMid><INid>(.*)</INid></ttIDRow></ttID>
So it looks like you need to know how much occurrences there are in that xml because they are all listed in the regexp?
Isn't there some way to select the values for NMid and INid without knowing how many occurrences there are of NMid and INid in that xml?
I guess that's a problem because you also need to define Measure-blocks for all occurrences and if you not know how many occurrences there are then there is a problem.

Maybe there's a better way to do what i want in RainMeter.
I want to have some file (I tried xml but may be another type of file) where I define all servers in our domain.
At any time I can add some or change some.
When I login to 1 off those servers I want to run RainMeter (that's no problem) but I want to always use some text to display depending on the server I have logged on.
I could put something on those servers (file/registry-value/....) but I do not want to do that.
I want everything in 1 place and that's my RainMeter folder that is on a shared-drive.
So that's why I tried with an xml-file with always 2 values: the servername and a text.
Then @logon I would run rainmeter that reads the xml, looks what entry has the same value as the servername and displays the value of the text related to this servername.

Maybe you have an idea how to do this with RainMeter.

I'm now trying a different approch, I've create a file for every server with only the text I want for that server in it
I then read that file with the QuotePlugin . This works but I would prefer to do all this is 1 file (so the xml of json or ??)

Regards
Didier
User avatar
balala
Rainmeter Sage
Posts: 7151
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Reading xml-data

balala » September 18th, 2018, 10:32 am

Den Duze wrote:I will try with this but I already have 1 question:
I see that you use the following Regexp:
RegExp=(?siU)<\?xml version="1.0"\?><ttID xmlns:xsi=".*"><ttIDRow><NMid>(.*)</NMid><INid>(.*)</INid><ttIDRow><NMid>(.*)</NMid><INid>(.*)</INid></ttIDRow></ttID>
So it looks like you need to know how much occurrences there are in that xml because they are all listed in the regexp?
Isn't there some way to select the values for NMid and INid without knowing how many occurrences there are of NMid and INid in that xml?
But there is. You have to use the Lookahead Assertion, described here.
Using this feature, you don't have to know the exact number, the first occurrences will be returned. How many, depends on how are you creating the RegExp.
So, here is a solution to your question: first define an Item variable into the [Variables] section of your code:

Code: Select all

[Variables]
Item=(?(?=.*<ttIDRow>).*<NMid>(.*)</NMid><INid>(.*)</INid>)
See that this variable is created in a way to use the Lookahead Assertion. The skin will check first if a new <ttIDRow> expression exists and if it does, the WebParser measures can read what is after it.
Modify the RegExp option of the parent WebParser measure, as it follows: RegExp=(?siU)#Item##Item##Item##Item##Item##Item#. Add as many #Item# variables as you want. I added here five, but you can add more or less, if needed. For each of them, the child WebParser measures will return the appropriate information if those exist, otherwise they will return nothing (in fact will return empty strings).
Just take care to create the needed child WebParser measures, which will return the found expressions.