XML parsing using Jquery where format is unknown - javascript

I dont know the XML format. but i want to parse it from a given XMLObject using Jquery. Is it possible if yes then how to do that.

You can do this using JSONP to convert your XML to a JSON object.
This blog posts covers it nicely and saves me rewriting the code.
http://weedygarden.net/2011/01/consuming-remote-xml-as-jsonp/

Related

JS: Convert XML or JSON to XML/RDF

In JavaScript, what's the easiest way to convert a String that holds XML or JSON into an XML/RDF file? I know I will probably have to use String parsing, but has this already been done or is there an easier way? I can find resources online on how to convert to RDF, but nothing about how to do it within JavaScript (IE: http://www.gac-grid.de/project-products/Software/XML2RDF.html) Any ideas?
Thanks in advance!
See if rdfquery or rdfparser fits your need, I did not use them and seem very old.
On the client side, we use json-ld

How to do Javascript access a local database in txt format

I am newbie working on a 100% js prototype. It consist of 3 docs: an html page full of xml tags, a small dictionary in a text file format, and a js file with jquery.
The js needs to parse the xml tags (no problem here) and look into the mini-dictionary list for available translations.
Which is the best way to implement the mini-dictionary list. (No more than 50.000 records). Is there a way to load the list into a memory database and access it from js? Which is the usual path to take in this case? What is the simplest and machine-independent way to do this?
Any directions as to where should I research are greatly appreciated.
I would suggest encoding mini-dictionary with JSON data format, and then using AJAX to get that file and parse it. But then you are risking someone will just copy whole dictionary and steal your work.
That is, if you are not using server side language, like PHP. If you are using it, then just store everything into database and request just specific words with AJAX.

XML construction using Javascript

Our app has a weird requirement which is to construct an xml using javascript and send that back to server as string.
I tried with jquery like this
$xmlT = $("<?xml version=\"1.0\" encoding=\"utf-8\"?><root></root>");
$root = $("<notebook></notebook>"); //.attr("title", roottitle).
$root.attr("title", title);
$root.attr("id", id);
$root.appendTo($xmlT);
but am not able to get the xml as string back from the above variable.
is there some way or library using which i can construct xml and access that as string?
Regards,
Jeez
You can do things like createElement() etc on the XMLDoc returned from XMLHttpRequest.responseXML
http://www.w3schools.com/dom/dom_nodes_create.asp
So perhaps you can use XMLHttpRequest without actually doing a request, so you can get an object to manipulate.
You could then serialise the XML Dom using the XMLSerializer (for firefox) or xmlNode.xml for IE (metioned here How do I serialize a DOM to XML text, using JavaScript, in a cross browser way?)
You could take a look at this plugin
I found these jquery plugins xml2json & json2xml which is close to what I was looking for, if not the same.
For more info check stackoverflow entryXML <-> JSON conversion in Javascript

JSON or XML or other data format with jQuery ajax()?

For a data send, where the return data contains potential updates for hundreds of elements on a page, is XML or JSON or another data format better, for usage with jQuery's various parsing formats (invoked via ajax() success)?
Check out this article, it outlines various pros/cons of XML, JSON and HTML when processing AJAX requests.
Personally I'd pick JSON as it uses less bandwidth & is easier to parse and use.
It sounds like a lot of data being returned so json. It's lighter and more compact. Plus it has native use instead of having to parse the xml and traverse it afterwards.
In javascript it is better to go with JSON because it is easier to code and less data to load from the server, unlike XML you have to write a code to parse the elements and fetch the values to your object and for every change in data tags or elements in XML you will need to modify your javascript code which means more coding and testing, unlike JSON all what you need is eval() and you are ready to go.

Javascript library for exporting XML

I'm currently using couchdb to store documents as JSON. One of my clients needs to grab XML (for now). Anyone know any good javascript libraries that can take a javascript object (or json string) and export valid xml?
Thanks!
json2xml.js: http://goessner.net/download/prj/jsonxml/

Categories

Resources