XBRL parser either by JAXB or any other - xbrl

I have worked on JAXB parsing with a simple XML file, but with my new project I have an XBRL file which is used for business record and that needs to parse. Is there any parsing technique for XBRL files? Any help would be appreciated!

XBRL is more than just an XML file. See my explanation in https://stackoverflow.com/a/38395549/2124628. Basically, it's a very large exercise to write an XBRL parser: You'd need to start with a parsing the XSD, Xlink and linkbase resources before you can even start parsing an XBRL file.
As I recommended in the other post: try leveraging an existing product, it's probably worth the investment.

there is a python package which parses XBRL
https://github.com/greedo/python-xbrl/

Related

Equivalent Xml for Json

I came across this service from stackoverflow
https://api.stackexchange.com/2.3/questions?fromdate=1519862400&todate=1522368000&order=desc&sort=activity&site=stackoverflow&tagged=python
I believe the source is from a database. How do I build an Xml to spit me out data in similar format?
I use the below logical lines
xmldoc.Load(xmlFileName);
Newtonsoft.Json.JsonConver.SerializeXmlNode(xmldoc);
Any recommendation of how to build the Xml which is a reverse process? My solutions are heavily dependant on Xml and flatFiles
According to https://api.stackexchange.com/docs the StackExchange API only supports JSON output, not XML. So you will have to convert the JSON to XML.
My own preference is to do this conversion "by hand" using XSLT 3.0 rather than using a standard library, because standard libraries often give you XML that's rather difficult to work with.

Validation of converted JSON against XML or XSD

I have an XML and XSD file. I am using Apache NiFi to convert XML to JSON. However, it is nested in many levels and hence I want to validate if the conversion is fine. I want to validate the same using XSD in Apache NiFi.
I will not be able to share the company sensitive information.
Is there any processor or script that I can use? there is an option of writing Python script in a processor called ExecuteScript.
Thanks in advance
There are two parts to your question.
Can JSON be validated via XSD?
Does nifi have a processor that validates JSON via XSD?
The first part already is answered here:
Validate JSON against XML Schema (XSD)
Now for the second part, depending on the solution you end up going with, neither one is implemented in a nifi processor, and attempting to use the ExecuteScript will not work for you because these require use of imported non-native modules. Instead you would need to create your own custom processor with java and import that into nifi which would solve your problem. This is all a bit labor intensive.
Alternatively, you could try a reverse conversion back to XML into an attribute and then validate that attribute content against the original XSD. This is a method I use a lot when writing unit tests. I haven't personally tried this in nifi, but it sounds like it would be possible and would likely be the least complicated solution.

Configuration file format with a schema?

I'm looking for a configuration file format with a schema. Something simple like YAML, but has a schema like XSD does for XML. Does this exist?
XML is a better serialization format than it is a configuration format but combined with XSD, it makes a powerful self-documenting configuration format.
Thanks!
One answer is Config4*. I recommend you read Chapter 2 (overview of the configuration syntax) and Chapter 3 (overview of the C++/Java API and overview of the schema language) of the Config4* Getting Started Guide to learn enough to decide if it suits your needs. Disclosure: I developed Config4*.
Another answer is Json, which now has its own schema language. I haven't used it, so I can't comment on its merits.

Converting JSON to XML using XSLT

Following is my requirement:
Application A is creating a JSON based on its Java Beans and sending to my Application.
I have to take this JSON and convert it into XML (XSD for this is completely different than my JSON structure) and send to Application B.
Solution 1) I am currently converting this json to xml using json.org library.Then using Apache-xalan and XSL stylesheet, I am converting this to xml format as required by App B.
Solution 2) Converting this json to Java Bean (JB1).Then converting this JB1 to another Java Bean (JB2) as per the xml structure required by Application B.Then convert JB2 to XML for app B.
Solution 3) Using Apache Xalan and Xerces to parse through the input json and make the XML in Java itself without using XSL.
Which is better approach (in simplicity of code, throughput )? As JSON becomes more complex, is it easy to use solution 1 ? Please suggest if there is better approach other than these 3 ?
XSLT 3.0 offers a built-in json-to-xml() function. Once you have the XML, you can easily transform it to your required format. It is implemented in Saxon 9.7 (PE or higher) and I believe in Exselt.
Solution 1: Yes. This is the conventional and best path for both simple and complex JSON and simple or complex targeted XML.
Solution 2: No. There's no reason to introduce Java Beans as an intermediate form, especially if you have no other need for Java Beans. This option unnecessarily introduces transformational and marshalling complexity.
Solution 3: No. Neither Xalan nor Xerces are designed to parse JSON; they are designed to parse XML.
There are sample programs that will map a JSON document into an equivalent XML document and back; I wrote one as a demo for Liberty's support of json-p (javax.json), using an XML vocabulary I called JinX (JSON in XML). That could be used as a pre/post processor wrapped around XSLT, if desired.
Better solutions are possible -- redefine XSLT to operate on JSON trees, for example -- but would take a bit more work.
JSON is, pure-and-simple, "a communications protocol." In other words, "it specifically exists(!) to allow 'arbitrary (JavaScript) data structures' to be conveyed between some-client and some-host," over "the HTTP(S) protocol."
Therefore: "it is not(!) XML," and therefore must never be considered to be "appropriate input to XSLT!"
"Thou shalt not mix Apples and Oranges!"
If you wish to apply "XSLT" technologies to a "JSON-derived" input (which is, by definition, "a data structure ...") then you must first, and "by whatever suitable means," convert that data structure into XML.

Restful: is there any case we should use xml over json

Json is better than xml for sure, i was wondering if there is any case we should use xml instead of json
If speaking in terms of REST, neither is better. Plain XML or plain JSON does not say anything about data transferred in either format. Though if you use well known formats like:
application/atom+xml
application/vnd.collection+json
comparison will boil down to which format suits your needs better.
If you compare XML to JSON from programming language perspective, yes XML adds extra layer between code and data, though nothing special. Oh and XML is little verbose and larger in terms of bytes.
XML has been around for a long time, and there's a lot of tools in place that JSON does not yet have, are not commonplace or ubiquitous.
XML has XSchema, RelaxNG, DTD. JSON does have an equivalent but it's not as common place.
XML has namespacing, which is great for mixing different document types. JSON does have some ideas on how to do namespacing (such as JSON-LD) but doing this correctly tends to take why people tend to enjoy JSON over XML for.
Namespacing in XML is everywhere, which gives you a very standard framework to re-use existing XML schemas for integration.
So I don't want to say, "you should do XML" or "you should do JSON", but I would rather say that if you need to integrate with existing XML systems, or you needs would strongly benefit from features such as namespacing, schemas, linking, re-use of existing XML documents, XSLT, etc... XML might be a better choice.