Syntax to 'find' in XML

0 favourites
  • 11 posts
  • 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

  • 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

  • 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,

  • 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?

  • 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?
  • 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, wow, it's work thanks,

    but to increase my knowledge, I still hope there are someone answer my second question...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • The equivalent would be: XML.NodeCount("/dict[word='" & word & "']/word")

  • blackhornet

    Thanks that's work!!!!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)