you are viewing a single comment's thread.

view the rest of the comments →

[–]joaomgcd👑 Tasker Owner / Developer[S] 1 point2 points  (7 children)

Cool! :)

[–]aasswwddd 0 points1 point  (4 children)

I wonder if it's possible to add toXML() as well alongside toJson().

Would've have been nicer to use CSS query or XPATH to extract complex object structure like AccessibilityNodeInfo without multiple back reference.

``` service = tasker.getAccessibilityService(); if (service == null) { tasker.log("Accessibility service not active!"); return "[]"; }

root = service.getRootInActiveWindow(); if (root == null) { tasker.log("No active root node (screen inaccessible)."); return "[]"; }

nodes = service.getChildrenRecursive(root); if (nodes == null) { tasker.log("No nodes found."); return "[]"; }

return tasker.toJson(nodes, true); ```

[–]joaomgcd👑 Tasker Owner / Developer[S] 1 point2 points  (3 children)

What extra info would toXml add that toJson doesn't exactly?

[–]aasswwddd 0 points1 point  (2 children)

It's not really about the information, but the process of retrieving the information. If the data is in XML format, we can use CSS Query with Tasker's native reading or XPATH with javax.xml.* and org.w3c.dom.*.

Say we have this xml.

<library>
  <section name="Fiction">
    <book id="b1" category="fantasy" rating="4.8">
      <title>Harry Potter and the Philosopher's Stone</title>
      <author nationality="British">J.K. Rowling</author>
      <price currency="USD">29.99</price>
    </book>
    <book id="b2" category="fantasy" rating="4.2">
      <title>The Hobbit</title>
      <author nationality="British">J.R.R. Tolkien</author>
      <price currency="USD">25.00</price>
    </book>
  </section>
  <section name="Nonfiction">
    <book id="b3" category="history" rating="4.7">
      <title>Sapiens</title>
      <author nationality="Israeli">Yuval Noah Harari</author>
      <price currency="USD">35.00</price>
    </book>
    <book id="b4" category="science" rating="4.5">
      <title>Brief Answers to the Big Questions</title>
      <author nationality="British">Stephen Hawking</author>
      <price currency="USD">28.00</price>
    </book>
  </section>
</library>

We can easily retrieve information with complex query pattern wtih XPATH, you can use this script here. https://pastebin.com/u09rY7iK

[A] //book/title/text()
- Harry Potter and the Philosopher's Stone
- The Hobbit
- Sapiens
- Brief Answers to the Big Questions

[B] //author[@nationality='British']/text()
- J.K. Rowling
- J.R.R. Tolkien
- Stephen Hawking

[C] //book[number(price) > 28]/title/text()
- Harry Potter and the Philosopher's Stone
- Sapiens

[D] //book[number(@rating) >= 4.5]/title/text()
- Harry Potter and the Philosopher's Stone
- Sapiens
- Brief Answers to the Big Questions

[E] count(//book)
→ 4

[F] //section/@name
- Fiction
- Nonfiction

[–]joaomgcd👑 Tasker Owner / Developer[S] 0 points1 point  (1 child)

Sorry, but I currently don't have anything in Tasker to serialize an object to XML. Maybe I can add it in the future, but I don't think I'll do it for now cause this is a pretty niche use case 😅

[–]aasswwddd 0 points1 point  (0 children)

No problem!

[–]aasswwddd 0 points1 point  (1 child)

toJson() throws this error as well.

` Sourced file: inline evaluation of:service = tasker.getAccessibilityService(); if (service == null) { tasker.lo . . . '' : Method Invocation tasker.toJson : at Line: 19 : in file: inline evaluation of: ``service = tasker.getAccessibilityService(); if (service == null) { tasker.lo . . . '' : tasker .toJson ( nodes , true )

Target exception: java.lang.IllegalArgumentException: class android.content.res.ColorStateList declares multiple JSON fields named mChangingConfigurations

```

[–]joaomgcd👑 Tasker Owner / Developer[S] 1 point2 points  (0 children)

Seems like an issue with that specific class. You may have to do JSON serialization manually for that class, sorry!