Syntax to 'find' in XML

Get help using Construct 2

Post » Mon May 13, 2013 11:44 am

Hello all, this is my first post in this forum, sorry if my english is bad

I want to create a simple word program, when you type a word, and click a button, give a result "YES" if that word is in the dictionary (in XML) and "NO" if not

And, How to find a word in XML? is there any XPath-like to find a word?

my xml structure:

<dict>
   <word>AB</word>
   <word>AC</word>
   <word>AD</word>
      .
      .
      .
</dict>

thanks for all answer

B
12
S
3
G
3
Posts: 8
Reputation: 2,590

Post » Mon May 13, 2013 1:06 pm

The best approach is either using Array (indexOf) or Dictionary (hasKey). I assume you just need to validate if the word from user is valid or not right? Regarding XML, it's a good idea to write them down on XML, but on start of layout you can parse and put each word entry to Array or Dictionary.

cmiiw
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Mon May 13, 2013 3:32 pm

is there any nice tutorial to use dictionary?
I know there are many method to store data like this, but when I search here, I just find tutorial to use XML,


B
12
S
3
G
3
Posts: 8
Reputation: 2,590

Post » Mon May 13, 2013 5:46 pm

I believe the fact there are very little tutorials regarding Dictionary is because it's quite simple to use. All you need to do is set a key and value. What else do you need to achieve?
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Mon May 13, 2013 8:05 pm

hmm.. but sorry I'm pretty unclear with dictionary,
may be you or someone could help me

this is my JSON after I convert the Last XML using PHPmyAdmin
[{"id": 1,"word": "a"}, {"id": 2,"word": "ab"}, ...

I was try or dictionary.get("id") or dictionary.get("word") or dictionary.get("a")

but the result is always 0

is it possible to find that "a" is exist (my case)? how to do that?malioboro2013-05-13 20:06:54
B
12
S
3
G
3
Posts: 8
Reputation: 2,590

Post » Mon May 13, 2013 10:03 pm

To answer your first question, if you were to use the XML to check whetner or not some word exists, you could use "Compare two values" and check if XML.NodeCount("/dict[word='AB']/word") is greater than 0.
B
45
S
16
G
18
Posts: 845
Reputation: 13,673

Post » Tue May 14, 2013 5:06 am

@magistross, wow, it's work thanks,

but to increase my knowledge, I still hope there are someone answer my second question...
B
12
S
3
G
3
Posts: 8
Reputation: 2,590

Post » Tue May 14, 2013 6:22 am

What I had in mind was use for each and iterate each 'word' element from your XML as Dictionary keys or Array values (just use 1 dimension or X only). And then you can check via Dictionary's hasKey or Array's indexOf. But that takes extra steps. Magistross way is much better.
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Tue Aug 26, 2014 12:26 pm

Magistross wrote:To answer your first question, if you were to use the XML to check whetner or not some word exists, you could use "Compare two values" and check if XML.NodeCount("/dict[word='AB']/word") is greater than 0.


@Magistross
I've try that, but it can't.
I just change 'AB' into a global variable.

Image
B
3
Posts: 2
Reputation: 179

Post » Tue Aug 26, 2014 1:46 pm

The equivalent would be: XML.NodeCount("/dict[word='" & word & "']/word")
ImageImage
B
66
S
19
G
121
Posts: 3,195
Reputation: 72,852

Next

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, MChiz, Radulepy and 0 guests