I need to know how I can parse a variable path in Flex 3 & e4X. For example, I have two XML strings where the name of one element is the only difference.
<NameOfRoot>
<NameOfChild1>
<data>1</data>
</NameOfChild1>
</NameOfRoot>
<NameOfRoot>
<NameOfChild2>
<data>2</data>
</NameOfChild2>
</NameOfRoot>
Currently I am accessing variables like this:
var data1:String = NameOfRoot.*::NameOfChild1.*::data;
var data2:String = NameOfRoot.*::NameOfChild2.*::data;
I would rather make this task more abstract so that if "NameOfChild3" is introduced I do not need to update the code. For example:
var data:String = NameOfRoot.*::{variable}.*::data;
Does anyone have insights into how this can be done?
Use the child property (LiveDocs example here):
var tagName:String = "NameOfChild1";
var data:String = NameOfRoot.child(tagName).data;
That's with no namespacing--not sure whether it's necessary in your case, but I assume you'd add some *::'s?
this also works:
var data:String = NameOfRoot..data;
but if you have more than 1 data node you'll have to sort some stuff out.
It looks like the ".*." operation will work. I wonder if this is the easiest way to handle this problem.
var data:String = NameOfRoot.*.*::data;
Related
I have in a global gdscript, and inside i have
var number1 = 0
var number2 = 0,
which normally could be accessed by any gdscript by global.number1 and global.number2.
Then i have a different script with a Dictionary inside that holds some values.
How can i make it work like this(see following):
var dict = {0: {path = "global.number1"}, {1: {path = "global.number2"}}
and then, instead of using several if-statements if i want to expand the number of objects in the dictionary, i can do this:
dict[n].path += 1
I dont really know what are you actually asking, but maybe you forgot to set the path to global in the second script?
Anyway you should clarify what's the question.
Please give me a hint how to parameterize a link element in QTP...As we can parameterize 'WebEdit' element/object ,can we parameterize 'Link' element/object and how can we?
By parameterizing, do you mean Parameterizing the properties of the Link element to identify it using Descriptive Programming? Or is it something else?? Please elaborate!!
You can build a function like the one below for each object type that you want to use.
public Function CreateLinkDescription(LinkInnerTextValue, LinkHrefValue)
Set objLink = Description.Create()
objLink("innertext").Value = LinkInnerTextValue
objLink("href").Value = LinkHrefValue
'Add any other properties that you want to specify in the same fashion as above
Set CreateLinkDescription = objLink
End Function
I have json that looks like:
myjson = {"queries":{"F.SP": 27}}
so with
queryResults = JObject.Parse(jsonString)
I can do
firstToken = queryResults.SelectToken("queries")
and get back the LinqJToken
{"F.SP": 27}
but I'm then stuck, because when I try
subToken = firstToken.SelectToken("F.SP")
I get Nothing. I'm guessing this is because JSON.net is looking for a token "F" with subtoken "SP".
I've also tried each of the following, to no avail
myToken = queryResults.SelectToken("queries.F.SP")
myToken = queryResults.SelectToken("queries[0].F.SP")
(queryResults.SelectToken("queries[0]") returns nothing, fwiw)
Any ideas?
EDIT: I have verified that the embedded "." is the problem; if I change the original json to
{"queries":{"FSP": 27}}
I can do
queryResults.SelectToken("queries").SelectToken("FSP")
no problem
If you have such names in JSON fields:
{"queries":{"F.SP": 27}}
You may use SelectToken escaping:
queryResults.SelectToken("queries").SelectToken("['F.SP']")
or
queryResults.SelectToken("queries.['F.SP']")
Here are more examples with escaping: http://www.newtonsoft.com/json/help/html/QueryJsonSelectTokenEscaped.htm
This won't return the token itself, but will return the value (which is probably what you're looking for anyway)...
queryResults.SelectToken("queries").Value<int>("F.SP");
Instead of trying to use SelectToken, how about an index search?
subToken = queryResults["F.SP"];
JObject obj = JObject.Parse(jsonstring);
var fsp = obj["queries"].First().First();
Not the most elegant but it gets the value.
I have 2 possibilities. It looks like these are the same (or I'm wrong). Which is better and why?
var quest1:DisplayObject = FrameCanvas.baseCanvas.addChild(app.questionmark1); //
quest1.x = posX; //
quest1.y = posY; //
or
app.questionmark1.x = posX;
app.questionmark1.y = posY;
In the first example quest1 is a reference to app.questionmark1 which you are adding to FrameCanvas.baseCanvas and then updating its x and y.
In the second example you are directly setting the x and y on app.questionmark1.
Both work to update app.questionmark1's x and y properties, but in the second example app.questionmark1 may not be on the stage unless you added it somewhere else in the code.
The second example is better because there's really not a reason to store a reference to app.questionmark1 as quest1 as you already can access it by app.questionmark1.
So I have something like this:
var xmlStatement:String = "xmlObject.node[3].#thisValue";
What mystery function do I have to use so that I can execute xmlStatement and get thisValue from that xmlObject? Like....
var attribute:String = mysteryFunction(xmlStatement);
P.S. I know eval() works for actionscript2, I need the as3 solution. :)
Unfortunately this is not possible in ActionScript 3. This however might be a solution: http://blog.betabong.com/2008/09/23/e4x-string-parser/
For your example it would be:
var attribute : String = String( E4X.evaluate( XMLList(xmlobject) , 'node[3].#thisValue' ) );