Just starting out? Need help? Post your questions and find answers here.
dougmo52
Posts: 2 Joined: Tue Feb 14, 2017 6:36 pm
Post
by dougmo52 » Tue Feb 14, 2017 6:46 pm
The following SB code and XML code work OK in PureBasic, but in SpiderBasic the debug message after the call to MainXMLNode never appears. It's like MainXMLNode never returns.
Code: Select all
hXML = LoadXML(#PB_Any,"TestXML.xml")
If hXML
If IsXML(hXML)
Debug "IsXML OK"
If XMLStatus(hXML) = #PB_XML_Success
Debug "XMLStatus OK"
Debug "Calling MainXMLNode"
hParent = MainXMLNode(hXML)
Debug "MainXMLNode returned"
If hParent
Children = XMLChildCount(hParent)
Debug "Parent has " + Str(Children) + " children"
hChild = ChildXMLNode(hParent)
GrandChildren = XMLChildCount(hChild)
Debug "First child has " + Str(GrandChildren) + " chldren"
EndIf
Else
Debug "XMLStatus Failed, " + XMLError(hXML)
EndIf
Else
Debug "IsXML failed, " + XMLError(hXML)
EndIf
Else
Debug "LoadXML(#PB_Any,'TestXML.xml') failed"
EndIf
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<Parent>
<Child>Child1
<GrandChild>GrandChild1</GrandChild>
<GrandChild>GrandChild2</GrandChild>
<GrandChild>GrandChild3</GrandChild>
<GrandChild>GrandChild4</GrandChild>
<GrandChild>GrandChild5</GrandChild>
</Child>
<Child>Child2
<GrandChild>GrandChild1</GrandChild>
<GrandChild>GrandChild2</GrandChild>
<GrandChild>GrandChild3</GrandChild>
<GrandChild>GrandChild4</GrandChild>
<GrandChild>GrandChild5</GrandChild>
</Child>
</Parent>
Peter
Posts: 1197 Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:
Post
by Peter » Tue Feb 14, 2017 7:07 pm
SB-Help wrote: The xml data is still not loaded, the callbacks binded to #PB_Event_Loading and #PB_Event_LoadingError will be called once the loading is done.
Code: Select all
EnableExplicit
Procedure Loading(Type, Filename.s, ObjectId)
Protected hParent
Protected Children
Protected hChild
Protected GrandChildren
Protected hXML = ObjectId
If XMLStatus(hXML) = #PB_XML_Success
Debug "XMLStatus OK"
Debug "Calling MainXMLNode"
hParent = MainXMLNode(hXML)
If hParent
Debug "MainXMLNode returned"
Children = XMLChildCount(hParent)
Debug "Parent has " + Str(Children) + " children"
hChild = ChildXMLNode(hParent)
GrandChildren = XMLChildCount(hChild)
Debug "First child has " + Str(GrandChildren) + " chldren"
EndIf
Else
Debug "XMLStatus Failed, " + XMLError(hXML)
EndIf
EndProcedure
Procedure LoadingError(Type, Filename.s)
Debug Filename + ": loading error"
EndProcedure
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
LoadXML(#PB_Any, "TestXML.xml")
Greetings ... Peter
dougmo52
Posts: 2 Joined: Tue Feb 14, 2017 6:36 pm
Post
by dougmo52 » Tue Feb 14, 2017 7:31 pm
Thanks for quick response. I did a search for Loading in SB help and didn't come up with anything although I do see Loading procedures in examples. I don't see a call to Loading so I presume the LoadXML call somehow triggers it internally. Where can I find more documentation on what SB calls require Loading procedures, and how such seemingly asynchronous loading behavior is typically synchronized?