Android Question XOM Library Error

RandomCoder

Well-Known Member
Licensed User
Longtime User
I've spent several evenings trying to get this to work and I now suspect that the fault is with my xml file which I am unable to do anything with as it is sent from a UPNP device.
I've attached two sample programs to demonstrate the problem. XOM_Weather uses the weather.xml file that is used in the XOM sample program to demonstrate usage of the library and this works correctly. XOM_UPNP is the same program but using an xml file obtained from one of my UPNP devices and I get an uninitialised fault each time I try to search for a value from a child node.

I also have another problem in that the devices on my network do not all adhere completely to the UPNP standard, i.e. the friendly name of a device could be listed as "friendlyname", "FriendlyName" or "friendlyName" or any other combination of caps/mixed caps. Is there a way to search for childelements case insensitively? I suspect that there is not, in which case I'll have to use the program I've already got to iterate over all the children and convert the local name to lower case before comparing against the entries I need.

Hope that makes sense to someone?

Thanks,
RandomCoder
 

Attachments

  • XOM_Weather.zip
    7 KB · Views: 220
  • XOM_UPNP.zip
    7.1 KB · Views: 247

warwound

Expert
Licensed User
Longtime User
Take a look at this updated version of your BuildDone Sub:

B4X:
Public Sub XOM_BuildDone(XOM_Doc As XOMDocument, Tag As Object)
   If XOM_Doc.IsInitialized Then
     Dim NameSpace As String="urn:schemas-upnp-org:device-1-0"
     ' Get root node and find children nodes itteratively
     Dim rootNode As XOMElement=XOM_Doc.RootElement
     GetChildren(rootNode, 0)
     ' Now try and find first child element called friendlyName
     Dim node As XOMElement=rootNode.GetFirstChildElementByNameAndNamespace("device", NameSpace)
     Log(node.GetFirstChildElementByNameAndNamespace("friendlyName", NameSpace).Value)
   Else
     Log("XOM_Doc is not initialized: "&LastException)
   End If
End Sub

It works!
First check if the XOMDocument is initialized - don't check if it's Null.
(I think i updated the library at some point and probably didn't post details on the forum :().
Next you need to use the methods which accept a namespace.

As for case of element names - there's no easy solution for you here.
XML is case sensitive and can't be treated as case insensitive.

Martin.
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Thank you both for the replies.
@Erel
I started to use the SAX library and have got to the point where I browse the UPNP media library. It was then that I thought that the XOM implementation might be more suitable.

@warwound
What is a namespace? Where can I learn more? I've already skimmed the XOM website but it didn't help me to resolve the problem. I'll have a tinker with the modified code tonight hopefully.

Cheers,
RandomCoder.
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Upvote 0

warwound

Expert
Licensed User
Longtime User
Search your XML document for urn:schemas-upnp-org:device-1-0 and you'll see where the document's namespace is declared.

Martin.
 
Upvote 0

Valeriy Lakhtin

Member
Licensed User
Take a look at this updated version of your BuildDone Sub:

B4X:
Public Sub XOM_BuildDone(XOM_Doc As XOMDocument, Tag As Object)
   If XOM_Doc.IsInitialized Then
     Dim NameSpace As String="urn:schemas-upnp-org:device-1-0"
     ' Get root node and find children nodes itteratively
     Dim rootNode As XOMElement=XOM_Doc.RootElement
     GetChildren(rootNode, 0)
     ' Now try and find first child element called friendlyName
     Dim node As XOMElement=rootNode.GetFirstChildElementByNameAndNamespace("device", NameSpace)
     Log(node.GetFirstChildElementByNameAndNamespace("friendlyName", NameSpace).Value)
   Else
     Log("XOM_Doc is not initialized: "&LastException)
   End If
End Sub

It works!
First check if the XOMDocument is initialized - don't check if it's Null.
(I think i updated the library at some point and probably didn't post details on the forum :().
Next you need to use the methods which accept a namespace.

As for case of element names - there's no easy solution for you here.
XML is case sensitive and can't be treated as case insensitive.

Martin.

You talked about the update XOM library? inform where I can download the latest version XOM library if I use API23
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Valeriy Lakhtin

Member
Licensed User
B4X:
Sub xomBuilder1_BuildDone(xomDoc As XOMDocument, Tag As Object)
   Log(LastException.Message)
   If xomDoc.IsInitialized Then
'   If Not (xomDoc=Null) Then   
        Msgbox(N_Group,"first test")
        Dim RootElem As XOMElement
        RootElem=xomDoc.RootElement
        Dim xomGroups As XOMElements, xomOptions As XOMElements
        xomGroups= RootElem.GetChildElementsByName("group")
        N_Group = xomGroups.Size
       Msgbox(N_Group & "ALL ОК","second test")
I want to know what prevents initialisation XOMdocument. In Log I see
-
java.lang.RuntimeException: Object should first be initialized (Exception).
-
 
Upvote 0

mouhaddab

Member
Licensed User
when i compile the sample project i get this error :
"A referenced library is missing: xom-1.2.10" any update for this library????
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
when i compile the sample project i get this error :
1. You should have created A NEW thread for this - new Question.
2. This is an old thread. No need to pull out such old threads. It will not help solving your issue.
3. You always should start a new thread and give enough details on the problem you have. Posting a sample app (in the IDE File->Export as zip) which shows the problem. Posting the error from the log you get and dont know what it could be.

Without seeing/running your code it is hard to give any congrete advices.

PD:

Use of XOM requires two additional jar files to be added to your B4A additional libraries folder: xom-1.2.10.jar and dtd-xercesImpl.jar, the forum attachment size limit prevents me from attaching these two files to this post so i have made them available from here.
 
Last edited:
Upvote 0
Top