Reading and Processing XML Files


John Clarke
I have some questions :

1. I am looking for a demo in the App Builder Samples that shows me how to read and process a local XML File. Does one exist ? If not where can I see an example ?
2. Will I have to include my file on the Others tab of the File Manager?

Thanks in advance


DecSoft

Hello John,

You can take a look at the FeedReader sample app. Can also take a look at the jQuery.parseXML() documentation. Note that we don't use this last one in the referred sample, we use other way, but, also using jQuery, which, as you know, it's available by default for our apps. Maybe this can be enough for your requirements.

Talking about the source of the XML, certainly, can be a file added by the "Others" tab in the Files manager, or may can proceed from internet, like you can see in the FeedReader sample app. In both cases you can use jQuery.get() or an HTTP client control in order to load the XML source.



John Clarke
Thanks David,

I was looking at the sample called "CordovaFile". It has the following code

Unfortunately this doesn't seem to work


DecSoft

Hello John,

The sample app that you refers must be compiled with Apache Cordova in order to properly works. But we no need Cordova in order to read a file previlusly added into the app Files Manager. Supose we add a "source.xml" file in the "Others" tab of the app Files manager. Then we can use an HTTP control in order to read it, but, also a "simply" jQuery.get() like below:

So, suposing we have a feed XML inside "source.xml", we can use jQuery in order to parse that XML source:



John Clarke
Thanks again David. I have something that is rather puzzling. I use the following code

The message for the error comes up and the error message contains "readyState":4,"responseText":" along with all of the text for the file it was meant to read. Suggesting that it had indeed read it.


DecSoft

Hello John,

Try to run the app and then press F12 in order to show the Developer Console: probably you can see it more information about the error. For example, if the XML is not well formed, the "fail" function is executed. So take a look at the Developer Console and see what can be happen exactly.

On the other hand, if you are responsible for the XML, maybe you can change it to a JSON file, because it's more easy to deal with a JSON file in Javascript, since the JSON source is a Javascript object variable ready to be used. If you need to use a XML, there is no problem: I suggest this because your file is a named "Config.xml"... so maybe you can prepare a JSON file for a configuration purpose.

You can take a look at the GetJson sample app to see how easy is to load an access to a JSON source / object.



John Clarke
Just one more question. When I specify for my browser plugin what do I need to use as the path to enable my code to read the XML File ?

DecSoft

Hello John,

I am not sure if we can access app's files specifically from the WebExtension: remember that the important point here is that we are running in different contexts. So, what we can do about this specific situation? I can think at least in two possibilities: 1º Use a remote URL, so the WebExtension can directly read it. 2º Use the messages that we can send from the app to the WebExtension and viceversa, in order to get the XML data of the file. So it's the app who read the file, but, pass the XML to the WebExtension when needed.


Todo el mundo puede leer el foro de soporte de DecSoft para aprender del mismo, sin embargo, sólo los clientes de DecSoft pueden abrir nuevos hilos. Compre una o más licencias de productos de DecSoft y obtendrá este y otros beneficios.

Este sitio utiliza "cookies" útiles para almacenar sus preferencias.

Bien. Ocultar esta nota. Obtener más información.