Android Question I can not open the XML file using the XOM library

Valeriy Lakhtin

Member
Licensed User
I try to read information from the XML file, I created a simple XML file

<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:eek:d="urn:schemas-upnp-org:device-1-0" generated="2015-12-11T15:07:54">
<S>
<in>A1</in>
</S>
<S>
<in>A2</in>
</S>
<S>
<in>A3</in>
</S>
<S>
<in>A4</in>
</S>
<S>
<in>D1</in>
</S>
</dataroot>

and activated it in the right pane file manager
but in the emulator CML file is not initialized. I think the problem with the file location?

Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("StartScreen")
' 'the BuildFromString method is used here as the BuildFromFile method cannot access files in assets
Dim XmlString As String
XmlString=File.GetText(File.DirAssets, "spravin.xml")

Dim XOMBuilder1 As XOMBuilder
XOMBuilder1.Initialize("XOMBuilder1")

XOMBuilder1.BuildFromString(XmlString, "", Null)

Msgbox(XOMBuilder1.IsInitialized,"")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub XOMBuilder1_BuildDone(XOMDoc As XOMDocument, Tag As Object)
If XOMDoc.IsInitialized Then

Dim RootElement As XOMElement=XOMDoc.RootElement
Dim ItemsElements As XOMElements
ItemsElements= RootElement.GetChildElementsByName("S")

N_Item = ItemsElements.Size

Else
Msgbox("File problem","")
End If
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
please use code tags when posting code
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Please use code tags [ CODE ] [ / CODE ] so it is easier to read code

B4X:
Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("StartScreen")
' 'the BuildFromString method is used here as the BuildFromFile method cannot access files in assets
Dim XmlString As String
XmlString=File.GetText(File.DirAssets, "spravin.xml")

Dim XOMBuilder1 As XOMBuilder
XOMBuilder1.Initialize("XOMBuilder1")

XOMBuilder1.BuildFromString(XmlString, "", Null)

Msgbox(XOMBuilder1.IsInitialized,"")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub XOMBuilder1_BuildDone(XOMDoc As XOMDocument, Tag As Object)
If XOMDoc.IsInitialized Then

Dim RootElement As XOMElement=XOMDoc.RootElement
Dim ItemsElements As XOMElements
ItemsElements= RootElement.GetChildElementsByName("S")

N_Item = ItemsElements.Size

Else
Msgbox("File problem","")
End If
End Sub
 
Upvote 0

Valeriy Lakhtin

Member
Licensed User
Thank you all for your advice CODE tag.
Why not XOM does not work
B4X:
XOMBuilder1.Initialize("XOMBuilder1")
XOMBuilder1.BuildFromString(XmlString, "", Null)
I checked my XML file is read into a string variable
 
Upvote 0

Valeriy Lakhtin

Member
Licensed User
Sanks,
I have correctedthe file but the problem persists

<?xml version="1.0" encoding="utf-8"?>
<dataroot>
<S>
<in>A1</in>
</S>
<S>
<in>A2</in>
</S>
<S>
<in>A3</in>
</S>
</dataroot>

B4X:
XOMBuilder1.Initialize("XOMBuilder1")
XOMBuilder1.BuildFromString(XmlString, "", Null)

this lines not work
 
Upvote 0

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Sanks,
I have correctedthe file but the problem persists

It works fine for me

B4X:
<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:eekd="urn:schemas-upnp-org:device-1-0" generated="2015-12-11T15:07:54">
<S>
<in>A1</in>
</S>
<S>
<in>A2</in>
</S>
<S>
<in>A3</in>
</S>
<S>
<in>A4</in>
</S>
<S>
<in>D1</in>
</S>
</dataroot>
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim XOMBuilder1 As XOMBuilder

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim XmlString As String
    XmlString=File.GetText(File.DirAssets, "spravin.xml")

    XOMBuilder1.Initialize("XOMBuilder1")

    XOMBuilder1.BuildFromString(XmlString, "", Null)

End Sub

Sub Activity_Resume
    'Msgbox(XOMBuilder1.IsInitialized,"")
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub XOMBuilder1_BuildDone(XOMDocument1 As XOMDocument, Tag As Object)
    If XOMDocument1.IsInitialized Then
      Log("XOMDocument is initialized")
    Dim RootElement As XOMElement
    RootElement=XOMDocument1.RootElement
    Dim childs As XOMElements
        childs = RootElement.GetChildElements
        For i= 0 To childs.Size-1
            Dim ele As XOMElement = childs.GetElement(i)
            'ele.GetAttributeValueByName("in")
            Log(ele.Value)
        Next
    End If    
End Sub
 

Attachments

  • xomex.zip
    7 KB · Views: 322
Upvote 0

Valeriy Lakhtin

Member
Licensed User
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim XOMBuilder1 As XOMBuilder

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim XmlString As String
    XmlString=File.GetText(File.DirAssets, "spravin.xml")

    XOMBuilder1.Initialize("XOMBuilder1")

    XOMBuilder1.BuildFromString(XmlString, "", Null)

End Sub

Sub Activity_Resume
    'Msgbox(XOMBuilder1.IsInitialized,"")
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub XOMBuilder1_BuildDone(XOMDocument1 As XOMDocument, Tag As Object)
    If XOMDocument1.IsInitialized Then
      Log("XOMDocument is initialized")
    Dim RootElement As XOMElement
    RootElement=XOMDocument1.RootElement
    Dim childs As XOMElements
        childs = RootElement.GetChildElements
        For i= 0 To childs.Size-1
            Dim ele As XOMElement = childs.GetElement(i)
            'ele.GetAttributeValueByName("in")
            Log(ele.Value)
        Next
    End If   
End Sub

not work

B4A version: 5.80
Parsing code. (0.00s)
Compiling code. (0.01s)
Compiling layouts code. (0.03s)
Generating R file. (0.03s)
Compiling generated Java code. (0.76s)
Convert byte code - optimized dex. (0.77s)
Packaging files. (0.21s)
Copying libraries resources (0.07s)
Found 8 resource files.
Signing package file (debug key). (0.46s)
ZipAlign file. (0.02s)
Installing file to device. Error
pkg: /data/local/tmp/xomex.apk
Failure [INSTALL_FAILED_VERSION_DOWNGRADE]
 
Upvote 0

Valeriy Lakhtin

Member
Licensed User
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim XOMBuilder1 As XOMBuilder

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim XmlString As String
    XmlString=File.GetText(File.DirAssets, "spravin.xml")

    XOMBuilder1.Initialize("XOMBuilder1")

    XOMBuilder1.BuildFromString(XmlString, "", Null)

End Sub

Sub Activity_Resume
    'Msgbox(XOMBuilder1.IsInitialized,"")
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub XOMBuilder1_BuildDone(XOMDocument1 As XOMDocument, Tag As Object)
    If XOMDocument1.IsInitialized Then
      Log("XOMDocument is initialized")
    Dim RootElement As XOMElement
    RootElement=XOMDocument1.RootElement
    Dim childs As XOMElements
        childs = RootElement.GetChildElements
        For i= 0 To childs.Size-1
            Dim ele As XOMElement = childs.GetElement(i)
            'ele.GetAttributeValueByName("in")
            Log(ele.Value)
        Next
    End If 
End Sub

Please check my test program but zip file with picture 5Mb
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Valeriy Lakhtin

Member
Licensed User
I don´t need. The code i uploaded is working for me.

the version of your app seems to have a lower versionnuber than the one already installed.
Increase version or remove the old app and then install it new

Youre test program worked OK jn my Google symulyator? but my version not work
 
Upvote 0
Top