Where can I find some documentation about this new XML function or can someone explain how to use it exactly ?
Here's a sample app...
and in the documentation: http://ai2.appinventor.mit.edu.ezproxy.canberra.edu.au/reference/components/connectivity.html#Web
XMLTextDecode(XmlText)
Decodes the given XML string to produce a list structure. <tag>string</tag> decodes to a list that contains a pair of tag and string. More generally, if obj1, obj2, … are tag-delimited XML strings, then <tag>obj1 obj2 ...</tag> decodes to a list that contains a pair whose first element is tag and whose second element is the list of the decoded obj’s, ordered alphabetically by tags.
Examples:
<foo><123/foo> decodes to a one-item list containing the pair (foo 123)
<foo>1 2 3</foo> decodes to a one-item list containing the pair (foo "1 2 3")
<a><foo>1 2 3</foo><bar>456</bar></a> decodes to a list containing the pair (a X) where X is a 2-item list that contains the pair (bar 123) and the pair (foo "1 2 3").
If the sequence of obj’s mixes tag-delimited and non-tag-delimited items, then the non-tag-delimited items are pulled out of the sequence and wrapped with a “content” tag. For example, decoding <a><bar>456</bar>many<foo>1 2 3</foo>apples<a></code> is similar to above, except that the list X is a 3-item list that contains the additional pair whose first item is the string “content”, and whose second item is the list (many, apples). This method signals an error and returns the empty list if the result is not well-formed XML.
XMLTextDecodeAsDictionary(XmlText)
Decodes the given XML string to produce a dictionary structure. The dictionary includes the special keys $tag, $localName, $namespace, $namespaceUri, $attributes, and $content, as well as a key for each unique tag for every node, which points to a list of elements of the same structure as described here.
The $tag key is the full tag name, e.g., foo:bar. The $localName is the local portion of the name (everything after the colon : character). If a namespace is given (everything before the colon : character), it is provided in $namespace and the corresponding URI is given in $namespaceUri. The attributes are stored in a dictionary in $attributes and the child nodes are given as a list under $content.
More Information on Special Keys
Consider the following XML document:
<ex:Book xmlns:ex="http://example.com/">
<ex:title xml:lang="en">On the Origin of Species</ex:title>
<ex:author>Charles Darwin</ex:author>
</ex:Book>
When parsed, the $tag key will be "ex:Book", the $localName key will be "Book", the $namespace key will be "ex", $namespaceUri will be "http://example.com/", the $attributes key will be a dictionary {} (xmlns is removed for the namespace), and the $content will be a list of two items representing the decoded <ex:title> and <ex:author> elements. The first item, which corresponds to the <ex:title> element, will have an $attributes key containing the dictionary {"xml:lang": "en"}. For each name=value attribute on an element, a key-value pair mapping name to value will exist in the $attributes dictionary. In addition to these special keys, there will also be "ex:title" and "ex:author" to allow lookups faster than having to traverse the $content list.
Thanks. I'm aware of what the XML structure is, but I'm struggling with what exactly needs to be populated in the two entries.
I'm assuming that the xmlText is the XML string value that I want to extract from, but what's exactly in "for component"?
I've tried to use a string with the 'key' value I'm looking for, but it gets rejected by the interface.
Use the Web1 block, not the generic Web block.
Indeed. Will do. Thanks
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.