Is there a way to read an XML file via HTML/Javascript on the client side?
I know I can add the XML data in the string in the javascript of the page. This solution works but it would be great if the xml file could be added like a css or a javascript file.
Is there a way to add a XML file like you would add a js file?
You could convert the XML into JSON or import it into a database first.
PHP has a library called Simple XML Parser that comes with most distributions. The interface is really straightforward.
Python also has a rich library called lxml to parse XML.
As the comments noted, accessing an XML file on the fly is probably not efficient.
Related
Hi I am currently working on delphi intraweb. I try to import html template file to the program instead of hard-code it by using components from tool palette. However, I cannot find anyway to interact with the html file satisfyingly. For example, I want to handle the values of input box in the html file or adding data to data table through delphi. Or should I perform the tasks through other aspects?
I am using IWTemplateProcessorHTML to load external html template to delphi but I couldnt figure out a way to pass values from the html file to delphi or from delphi to that html file in run-time. There is not coding involved yet.
Thanks.
Im trying out the MarkLogic Java API and would want to bulk upload some files with the extension .csv
I'm not sure what to use, since the Java API only supports JSON, XML, and TXT files.
How do I batch upload files using the MarkLogic Java api? Do i convert everything to JSON?
Do i convert everything to JSON?
Yes, that is a common way to do it.
If you would like additional examples of how you can wrangle CSV with the Java Client API, check out OpenCSVBatcherExample and JacksonDatabindTest.testDatabindingThirdPartyPojoWithMixinAnnotations. The first demonstrates converting the csv to XML and using a custom REST extension. The second example (well, unit test...) demonstrates converting the csv to JSON and using the batch upload (Bulk Writes) capabilities Justin linked to.
If you have CSV files on your filesystem, I’d start with mlcp, as suggested above. It will handle all of the parsing and splitting into multiple transactions/batches for you. Take a look at the mlcp documentation for more details and some example configurations.
If you’d like more control over the parsing and splitting logic than mlcp gives you out-of-the-box or you’re getting CSV from some other source (i.e. not files on the filesystem), you can use the Java Client API. The Java Client API allows you to efficiently write batches using a WriteSet. Take a look at the “Bulk Writes” example.
According to your reply to Justin, you cannot use MLCP because it is command line and you need to integrate it into a web portal.
Well, MLCP is released as open cource software under the Apache2 licence. So if you are happy with this licence, then you have the source to integrate.
But what I see as your main problem statement is more specific:
How can I create miltiple XML OR JSON documents from a CSV file [allowing the use of the java API to then upload them as documents in MarkLogic]
With that specific problem statement:
1) have a look at SplitDelimitedTextReader.java from the mlcp source
2) try some java libraries for this purpose such as http://jsefa.sourceforge.net/quick-tutorial.html
It's 100MB, so here's a portion of it:
https://drive.google.com/file/d/0B1GVNHhYNzBINWl4TVFOejhtbEE/view?usp=sharing
It doesn't come with an extension, I added the xml extension to it.
What file type is this and how can I parse it? I tried untangle with python and ran into errors.
The file you reference is an XML export of a MediaWiki.
See also the MediaWiki page form XSD.
You can parse it with a standard XML parser, which is available in most languages, including Python.
I need to create a brochure for a conference. I export information from two databases that create two XML documents. I need to export both to one HTML / Latex document. How can I do this?
If you want to merge both the XML in one. Then you need to convert both XML's to JSON object using javascript. And do some merging operations on that JSON. Then convert back to XML.
U can get JS libraries to convert from json to xml and xml to json.
This is what XSLT is for but that topic is something you will need to study up on to learn to do that and it isn't something you'll learn overnight.
Is there any naming convention for a json schema file extension? XML has .xsd (XML Schema Definition), what should json schema files have, .jsd (JSON Schema Definition)?
From Gary Court:
I personally use .schema.json, but there is no official file
extension. The official mime type however is
"application/schema+json".
Update 2022Nov
application/schema+json and application/schema-instance+json will be published by an IETF RFC.
According to current proposal, both json and schema.json extensions are supported. I still find it quite inconvenient for processing based on conventions to have a dot within an extension.
Previous comment
According to the last draft (v4), there is not a new extension proposed for files storing json-schemas. .json extension is used profusely within that document. .json is also the preferred extension in validators (PHP, Ruby, Python).
So I think that .json should be the preferred option in absence of an official/standard new extension.
From https://json-schema.org/understanding-json-schema/basics.html#id3
Since JSON Schema is itself JSON, it’s not always easy to tell when
something is JSON Schema or just an arbitrary chunk of JSON. The
$schema keyword is used to declare that something is JSON Schema. It’s
generally good practice to include it, though it is not required.
So you can use .json as the file extension for JSON schema but maybe with a $schema keyword (although optional) for better distinction.
I've started using .jschema after I had a run-in with an extension-based JSON Schema parser that automatically added id's to external RAML examples which are also .json files.
They are a specific format, after all. HTML is XML, which is UML, and we use a different file extension for each of those.
My suggestion is .jsd or .jsonsd standing for Json Schema Document.
I followed the way XML Schemas are named XSD (Xml Schema Document)
A JSON Schema is a valid JSON file so the extension .json is OK.
Then, the first attribute of your file should be '$schema' to declare the version of the specification you are using. Eg.
{
"$schema": "https://json-schema.org/draft/2019-09/schema",