XOMBuilder does not recognize XML file

realblue

Member
Licensed User
Longtime User
Hi guys,

I have the below XML file and trying to parse with XOM library but in the builddone event I get XOMDocument null.

Any ideas?

<Connections>

<ConnectionInfo>
<DatabaseType>2</DatabaseType>
<DataSource>rF+QZkYHYTxpTxxRGho1Uf8KyFjIwtn4bQ9jbn44k/w=</DataSource>
<Catalog>pGt/AthCX3AUn+hjFjhRbw==</Catalog>
<Provider>tsHcKM6kxKatJFUiazs36Q==</Provider>
<ConnType>5llZWbw0W/J//lSUEvQhfw==</ConnType>
<WebServisUrl>eQK6Zg5qcTwyOrOsZYsQKANkHVbwmdvTTxgLOqkHIftMd6Iam1mhX9Pbwk9gJ//LHGWn2Tte2NNzaHfulaUoDg==</WebServisUrl>
<UserName>y+zLgT1Ye2EY7yrocQB6zQ==</UserName>
<Password>zKvhl43B6IAmuBUTetMwog==</Password>
<Name>SOYAK OLYMPIAKENT</Name>
</ConnectionInfo>

<ConnectionInfo>
<DatabaseType>2</DatabaseType>
<DataSource>PDbU/2kt6ImGWcYCr7OT/ynaqCUSjFQD8NWKMllG6XE=</DataSource>
<Catalog>8Qrs+SjWl5Lbtj0/N0t7NA==</Catalog>
<Provider>tsHcKM6kxKatJFUiazs36Q==</Provider>
<ConnType>5llZWbw0W/J//lSUEvQhfw==</ConnType>
<WebServisUrl>WVE2PYupJdZM2c1/KgT+F7sA37ZVYsixb+2hYhB0e5v3shzkB/zMxQs72OEdV3e/lv15ReuZm4aijJT/CGhOpw==</WebServisUrl>
<UserName>y+zLgT1Ye2EY7yrocQB6zQ==</UserName>
<Password>zKvhl43B6IAmuBUTetMwog==</Password>
<Name>SOYAK SIESTA 1. BÖLGE</Name>
</ConnectionInfo>

</Connections>
 

warwound

Expert
Licensed User
Longtime User
Uncheck the 'Filter' checkbox in the b4a IDE and run your code again.
Do you see any exceptions logged?

Can you post your code so i can take a look?

Martin.
 
Upvote 0

realblue

Member
Licensed User
Longtime User
Ok I got it worked but I think there is still something wrong.

Here is the code that didn't work
B4X:
      Dim XOMBuilder1 As XOMBuilder
               XOMBuilder1.Initialize("XOMBuilder1")
      XOMBuilder1.BuildFromFile(File.DirDefaultExternal & "\connections.xml",Null)

Here is the code that works
B4X:
       Dim bufstr As String
       bufstr=File.ReadString(File.DirDefaultExternal, "connections.xml")
       Dim XOMBuilder1 As XOMBuilder
           XOMBuilder1.Initialize("XOMBuilder1")
       XOMBuilder1.BuildFromString(bufstr, "", Null)

By the way the file I am reading is downloaded from an FTP server.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
What do you mean by but I think there is still something wrong?

Does the BuildDone event get raised and passed a valid XOMDocument object?
Is the XOMDocument not quite right - does it look as though your XML has not been correctly parsed?
If so is it a character encoding problem?

Have you tried the XOMBuilder BuildFromURL method - does it retrive the XML from your FTP server (don't forget you'll need to add the permission android.permission.INTERNET to your project if it is not already added in order to use this method).

Have you validated your XML file to ensure it is well formed?
XML Validation: XML Validation

Martin.
 
Upvote 0

realblue

Member
Licensed User
Longtime User
Hi Martin,

The same XML file was parsed with XOMBuilder1.BuildFromString method but not parsed with XOMBuilder1.BuildFromFile method.

I think there are some differences between two methods.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

I've just updated the XOM library: http://www.b4x.com/forum/additional-libraries-classes-official-updates/23551-lib-xom.html#post174161

In your XOMBuilder BuildDone event Sub you can now get the text of any exception that occurred while trying to build the XOMDocument:

B4X:
Sub XOMBuilder1_BuildDone(XOMDocument1 As XOMDocument, Tag As Object)
   If XOMDocument1=Null Then
      '   XOMDocument1 will be Null if an error has occurred
      Log("An error has occured and the XOMDocument has NOT been created")
      Log(LastException)
   Else
      Log("XOMDocument is NOT Null")
      ' proceed to work with the XOMDocument
   End If
End Sub

Hopefully the text of the exception will throw some light on what's going wrong here.

Martin.
 
Upvote 0

realblue

Member
Licensed User
Longtime User
Hi Martin,

Thank you for the update.

When I try the code I got (FileNotFoundException) java.io.FileNotFoundException: /mnt/sdcard/Android/data/b4a.example/files\connections.xml (No such file or directory)

which was my mistake to use "\" instead of "/".

Sorry I took your time. May be you consider auto correcting path separator char. :)

Thank you for the support.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi again.

Take a look at the documentation for the File object: Basic4android - Files (Core).

File.Combine

Combine (Dir As String, FileName As String) As String
Returns the full path to the given file.
This methods does not support files in the assets folder.


So your code would have read:

B4X:
XOMBuilder1.BuildFromFile(File.Combine(File.DirDefaultExternal, "connections.xml"), Null)

And now the file separator is unimportant - it's handled silently by the Combine method.

Martin.
 
Upvote 0
Top