Because you can

aeric

Expert
Licensed User
Longtime User
Because JSON format API is the standard format, doesn't mean it is the only format to use.

I never seen any article online talking about XML to power the API (for web app) .

Of course many will debate that JSON is more lightweight and supported by parser from many major programming languages.

XML is more uglier, verbose, takes up more file size and difficult to parse.

This doesn't mean we should ignore this format.

Maybe some systems are still using SOAP.

So B4X should also (already true) have XML supported when building backend API.

But to make it easier to use, a library or framework can help you get the job done.

So Pakai framework is worth to consider. Because you can... use XML as API.
 
Last edited:

aeric

Expert
Licensed User
Longtime User
Not forgetting about RSS feeds and site map.
Honestly I don't use both. 😅
 

Magma

Expert
Licensed User
Longtime User

aeric

Expert
Licensed User
Longtime User
Hi aeric
Pakai framework - is your project web server API ? renamed / renewed :)

Well what do you mean u can use XML as API... you mean having REST API waiting for xml posts ? or something different ?
Yes, Pakai is the new name!

I mean instead of JSON, which parsed by Javascript JSON.Stringify() method in browser, the JavaScript reads XML response returned from the server.
 

Magma

Expert
Licensed User
Longtime User
Yes, Pakai is the new name!

I mean instead of JSON, which parsed by Javascript JSON.Stringify() method in browser, the JavaScript reads XML response returned from the server.
Is there anyway to convert json to XML...
or general mapping json to json that seems in some points...

with a method style like mapping ?
it can be feature....

For example you will see it also in your country... with the the Providers of Invoicing (if your country will give that at 3rd providers)... if they have different APIs will be useful to have matching, also an AI matching for first time...

for example <amount> </amount> (xml) -----> to amount: (json)
or for AI:
<amount></amount> -----> to amountvalue:

...can be a tricky... but this will be a life saver....
 

aeric

Expert
Licensed User
Longtime User
In other words, it means you can test the API directly from the frontend by just adding 1 line of code and it is good to go!
 

aeric

Expert
Licensed User
Longtime User
Is there anyway to convert json to XML...
or general mapping json to json that seems in some points...

with a method style like mapping ?
it can be feature....

For example you will see it also in your country... with the the Providers of Invoicing (if your country will give that at 3rd providers)... if they have different APIs will be useful to have matching, also an AI matching for first time...

for example <amount> </amount> (xml) -----> to amount: (json)
or for AI:
<amount></amount> -----> to amountvalue:

...can be a tricky... but this will be a life saver....
Yes, it is easy! B4J already have Map2xml.
But the problem is at js side. The JS to read json and xml are different!
In my template, if you change the default content type from json to xml, the frontend will break.
 

Magma

Expert
Licensed User
Longtime User

Magma

Expert
Licensed User
Longtime User
What about automatic matching.?.. ofcourse xml elements-nodes having inside of them extra elements nodes (lists) or lines... will be difficult... but if some magic of AI could do that... i am sure AERIC-I will be better :)
<lines>
<0>
<field> </field>
<price> </price>
</0>

<1>
<field> </field>
<price> </price>
</1>


<2>
<field> </field>
<price> </price>
</2>
</lines>
 

aeric

Expert
Licensed User
Longtime User
not a problem... if having different url /convertxml /convertjson (that will be only for developers)
Because I don't want developer to do more work or coding when using my templates.
 

aeric

Expert
Licensed User
Longtime User
What about automatic matching.?.. ofcourse xml elements-nodes having inside of them extra elements nodes (lists) or lines... will be difficult... but if some magic of AI could do that... i am sure AERIC-I will be better :)
<lines>
<0>
<field> </field>
<price> </price>
</0>

<1>
<field> </field>
<price> </price>
</1>


<2>
<field> </field>
<price> </price>
</2>
</lines>
Automatic?
I already have RequestDataXML method even in WebApiUtils v3.05 !
 

Magma

Expert
Licensed User
Longtime User
Automatic?
I already have ReadDataXML method!
What exactly do that?

May be i wasn't clear... is someway difficult that i am asking...
1. I am having a REST-API that needs json and have specific fields... i have an example of post (of it)
2. I am having an other REST-API that need xml and have different fields... some may be are the same or the name feels like json post..

Can automatically - magic match them ?
 

Magma

Expert
Licensed User
Longtime User
What exactly do that?

May be i wasn't clear... is someway difficult that i am asking...
1. I am having a REST-API that needs json and have specific fields... i have an example of post (of it)
2. I am having an other REST-API that need xml and have different fields... some may be are the same or the name feels like json post..

Can automatically - magic match them ?
actually magic match the values i gave... to each other... give json or xml return me a new post of a different json - xml
 

aeric

Expert
Licensed User
Longtime User
What exactly do that?

May be i wasn't clear... is someway difficult that i am asking...
1. I am having a REST-API that needs json and have specific fields... i have an example of post (of it)
2. I am having an other REST-API that need xml and have different fields... some may be are the same or the name feels like json post..

Can automatically - magic match them ?
You can write your own mapping by looping through the keys.
Because once you have the input from client, you converted it to Maps and Lists, everything is straight forward.

The RequestDataXml sub is added to the library allows the server to transform the XML body from a client request into data that easy to work with.

Regardless of what input or output format are!
JSON -> JSON
JSON -> XML
XML -> XML
XML -> JSON

Or even query parameters as input in array or string forms, output to non json or xml response.

All that is up to you!
 

Magma

Expert
Licensed User
Longtime User
You can write your own mapping by looping through the keys.
Because once you have the input from client, you converted it to Maps and Lists, everything is straight forward.

The RequestDataXml sub is added to the library allows the server to transform the XML body from a client request into data that easy to work with.

Regardless of what input or output format are!
JSON -> JSON
JSON -> XML
XML -> XML
XML -> JSON

Or even query parameters as input in array or string forms, output to non json or xml response.

All that is up to you!
You can write your own mapping by looping through the keys <-that exactly if can be "automatically" and then give the option to save it as template to make some changes will be "magic" and life saver !
 

aeric

Expert
Licensed User
Longtime User
You can write your own mapping by looping through the keys <-that exactly if can be "automatically" and then give the option to save it as template to make some changes will be "magic" and life saver !
I believe it can be done automatically without using a loop.
You may start a new question if you want.
 

Magma

Expert
Licensed User
Longtime User
I believe it can be done automatically without using a loop.
Not in all cases... but yes.. sometimes... but the difficult are the different fields, types, or may differences that need the target API of any Provider... so that, if feeding an AI system with some xml, json examples will automatic create a mapping for you... that "feed"... will be nice have it in one place like yours
 

aeric

Expert
Licensed User
Longtime User
Not in all cases... but yes.. sometimes... but the difficult are the different fields, types, or may differences that need the target API of any Provider... so that, if feeding an AI system with some xml, json examples will automatic create a mapping for you... that "feed"... will be nice have it in one place like yours
If I understand you correctly, I have already incorporated a similar idea in WebApiUtils v4.
Let say you have a property for ResponseKeys.
You can specify a list of keys to generate the required output based on the order in an array or list and you map back the keys. You can also have custom key name that override the original key.
 

Magma

Expert
Licensed User
Longtime User
ok.. here are 3 different providers... the last one (is xml - our MYDATA Provider / old invoicing for our country)
the first two are ...they are different company providers..

How easy is automatically match the fields/elements with the right values ?
have in mind this is 1 from 30 (invoices-receipts forms that need) and the providers are about 30...
 

Attachments

  • timologia xml - json - parochos - ilyda - mydata.zip
    27.8 KB · Views: 82
Top