Hi all,
Sorry if this is a particularly dense question.... I am trying to find a way of reading a local xml file into my app, and then adding additional elements to it, as additional data is entered by the user.
Context: The user will need to enter multiple (up to 30) samples with a range of values (date, time, sample type etc, potentially up to ~50/sample). Rather than try to record the values for all samples into an array and build the xml with a single builder, I thought it would be easier to enter the values into the xml as each sample entry is completed, and then enter the next sample with a new builder, parsed from the previous file. The xml layout is predefined, as per the database that I am passing data to.
I have been able to use the xmlBuilder to build the file in the first place (ie the first sample) , but I am getting stuck with parsing the file back into the xmlBuilder. I believe I need to use xmlBuilder.Parse, as mentioned here:
https://www.b4x.com/android/forum/threads/anyone-using-xmlbuilder-with-b4a.16277/
in posts #9 and #10.
However, the .Parse requires an InputSource object, and I cannot figure out how to get the InputStream from the xml into an InputSource object... - When I tried to use File.OpenInput I got an error during compiling:
The only other reference to them that I can find is through the xmlSax library, with .Parse and .Parse2:
https://www.b4x.com/android/forum/threads/xml-parsing-with-the-xmlsax-library.6866/
(post #15) mentioned as passing the stream to an InputSource object.
That made me think of trying:
but realised pretty quickly that it's trying to pass a void value. This is where I come up against the limits of fumbling in the dark...
This is probably a result of my novice coding, but any thoughts as to how I can move forward would be appreciated!
For reference I have attached a copy of the xml format that was supplied by the target database as a template, and the test program in which I am trying to figure out the xml coding...
Cheers,
Ben.
Sorry if this is a particularly dense question.... I am trying to find a way of reading a local xml file into my app, and then adding additional elements to it, as additional data is entered by the user.
Context: The user will need to enter multiple (up to 30) samples with a range of values (date, time, sample type etc, potentially up to ~50/sample). Rather than try to record the values for all samples into an array and build the xml with a single builder, I thought it would be easier to enter the values into the xml as each sample entry is completed, and then enter the next sample with a new builder, parsed from the previous file. The xml layout is predefined, as per the database that I am passing data to.
I have been able to use the xmlBuilder to build the file in the first place (ie the first sample) , but I am getting stuck with parsing the file back into the xmlBuilder. I believe I need to use xmlBuilder.Parse, as mentioned here:
https://www.b4x.com/android/forum/threads/anyone-using-xmlbuilder-with-b4a.16277/
in posts #9 and #10.
However, the .Parse requires an InputSource object, and I cannot figure out how to get the InputStream from the xml into an InputSource object... - When I tried to use File.OpenInput I got an error during compiling:
B4X:
Dim x As XMLBuilder
x=x.parse(File.OpenInput(File.DirInternal,"Test1.xml"))
B4X:
Parsing code. 0.06
Compiling code. 0.89
Compiling layouts code. 0.15
Generating R file. 1.19
Compiling debugger engine code. 2.15
Compiling generated Java code. Error
B4A line: 354
x=x.parse(File.OpenInput(File.DirInternal,\
javac 1.7.0_71
src\b4a\example\main.java:387: error: inconvertible types
_x = _x.parse((org.xml.sax.InputSource)(anywheresoftware.b4a.keywords.Common.File.OpenInput(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"Test1.xml").getObject()));
^
required: InputSource
found: InputStream
1 error
The only other reference to them that I can find is through the xmlSax library, with .Parse and .Parse2:
https://www.b4x.com/android/forum/threads/xml-parsing-with-the-xmlsax-library.6866/
(post #15) mentioned as passing the stream to an InputSource object.
That made me think of trying:
B4X:
Dim x As XMLBuilder
Dim Parser As SaxParser
x=x.parse(Parser.Parse(File.OpenInput(File.DirInternal,"Test1.xml"),"Parser"))
but realised pretty quickly that it's trying to pass a void value. This is where I come up against the limits of fumbling in the dark...
This is probably a result of my novice coding, but any thoughts as to how I can move forward would be appreciated!
For reference I have attached a copy of the xml format that was supplied by the target database as a template, and the test program in which I am trying to figure out the xml coding...
Cheers,
Ben.