DOMData Extender (Alpha?)

Started by JTaylor, January 18, 2021, 06:16:03 PM

Previous topic - Next topic

JTaylor

Not disagreeing.  Always more than one way to skin a cat.

Jim

td

Hope my cat didn't read this...
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

Might make him think twice before misbehaving.

Quote from: td on January 21, 2021, 09:25:49 AM
Hope my cat didn't read this...

JTaylor

Here is the latest.   Added more to XML stuff as well as fix/tweak here and there.  Can now extract attributes as well as an Array and CSV output from 2 levels of XML.  Now off to use it in a project and see what I have missed.

   http://www.jtdata.com/anonymous/DomData.zip

Jim

JTaylor

After attempting to use the XML stuff I have renamed most all the XML functions.  Also, I don't think I like the way this library does things so need to do some better "wrapping" as I don't really like much of what I have done so far.   I think I stuck too closely to the library way of doing it.   Wish the previous one had worked but could never figure out why it would work one time and then immediately get gibberish the next run.

http://www.jtdata.com/anonymous/DomData.zip

Jim

stanl

Things are moving along well here. As for a treeview object I kinda agree with Tony that it is not necessary. Unless I missed it, some sort of count() function would be helpful. Using the Json file:
tree  = dmjGetElementMap("/features/0")  creates a tab-delimted variable that can become a WB map. But I'd like a way to know there are 4 elements.  But, it could be a dumb question.

JTaylor

Thought about adding that, and intended to put something in the Help, but since you can do:

    cnt = ArrInfo(treemap,1)

I decided not to bother.  I have added that to the help file so thanks for the reminder.

Jim

JTaylor

Glad to hear it.   Let me know if there is something I can do to make what you mentioned easier.  Still not sure what more you need so just let me know, with pictures :)

Jim

Quote from: stanl on January 22, 2021, 03:23:01 AM
Things are moving along well here. As for a treeview object I kinda agree with Tony that it is not necessary. Unless I missed it, some sort of count() function would be helpful. Using the Json file:
tree  = dmjGetElementMap("/features/0")  creates a tab-delimted variable that can become a WB map. But I'd like a way to know there are 4 elements.  But, it could be a dumb question.

stanl

Maybe I missed a version...but
Code (WINBATCH) Select


AddExtender("wbdomdata.dll")
cJson = Dirscript():"nc.json"
cFile = Dirscript():"tree.txt"


dmParse(FileGet(cJson),@dmJSON)


tree  = dmjGetElementMap("/features/0")
cnt = ArrInfo(tree,1)







will error that tree is not an array. Or I would have figured it out.

JTaylor

You have to create the Map.   I am told that there are plans to make Maps available as part of the Extender SDK but not sure of the timeline on that option.  Once that occurs I can send back a Map and the extra step won't be necessary.

jim


tree  = MapCreate(dmjGetElementMap("/features/0"),@TAB,@CR)

stanl

Quote from: JTaylor on January 22, 2021, 03:16:38 PM
You have to create the Map.   


Yep. I had my RFM moment. Stepping through the tree is just a matter of developing a recursion structure as well as a structure for output. Your Extender provides all that is needed - the iteration is a matter of style or a teachable moment ::)


more clumsy code below, just going to continue plugging things in to see what shakes out: Eventually see multiple threads for Json, XML, HTML....
Code (WINBATCH) Select


AddExtender("wbdomdata.dll")
cJson = Dirscript():"nc.json"
dmParse(FileGet(cJson),@dmJSON)


;choose element to test
element = "/features/0" ;will return sub-tree
                        ;stepping through sub-tree will get to single element/item pair


;element = "/features/0/id"  ;will return selected element as item
tree  = MapCreate(dmjGetElementMap(element),@TAB,@CR)
cnt = ArrInfo(tree,1)


If cnt==0
   fld = ItemExtract(ItemCount(element,"/"),element,"/")
   Message(element,fld:@TAB:dmjGetValue(element))
Else
   For i = 0 to cnt-1
      Message("Item:":i+1,tree[i])
   Next
Endif


Exit

JTaylor

I am sure you know this but on the outside chance you don't and for the sake of thoroughness you can also do the following and avoid the counters.

Code (winbatch) Select


   Foreach leaf in tree
      Message("Item: ", tree[leaf])
   Next


stanl

Quote from: JTaylor on January 23, 2021, 06:01:06 AM
I am sure you know this but on the outside chance you don't and for the sake of thoroughness you can also do the following and avoid the counters.

Code (winbatch) Select


   Foreach leaf in tree
      Message("Item: ", tree[leaf])
   Next




Yes, I know that. Having a count is more important, at the moment...