-1

Is it possible to create an xml file using jQuery or will I have to use server side functions?

SomeKittens
  • 38,868
  • 19
  • 114
  • 143
anjel
  • 1,355
  • 4
  • 23
  • 35
  • 1
    It depends what you mean by "file". To use the literal definition, no - you cannot create server-side files purely using client-side JavaScript. However, creating an XML string is simple. –  Aug 03 '12 at 19:35
  • i didnt want to say file .what i mean create an xml string.but after i will be able to use Xquery to query like i would do in a database – anjel Aug 03 '12 at 19:51

3 Answers3

1

JQuery is a javascript library which runs on the client side/browser. To write to the server you need to use a server side tool. ex. ASP, Python, Php.

Brandon Poole
  • 382
  • 2
  • 7
0

Use jquery ajax to send some data to a server page (ASP.NET/ PHP) and create the XML there.

The below sample makes a call to an ASP.NET MVC action method where i am creating an XML document using the data passed and saving it the disk.I am using the LINQtoXML API for this example

 $.post("Home/CreateXML", { name : "Angel", age : "22" } function(data){
       alert("Response from server is : "+data);
 });

And in your Server side,

public ActionResult CreateXML(string name,string age)
{
  XElement elm=new XElement("SomeXML",
                     new XElement("Name",name),
                     new XElement("Age",age));

 elm.Save("C:\\somexml.xml") 
 return Content("XML Created and saved in disk!");   
}

Executing this will create an XML in this form

 <SomeXML>
    <Name>Angel</Name>
    <Age>Angel</Age>
 </SomeXML>
Shyju
  • 214,206
  • 104
  • 411
  • 497
0

You can create xml content for your xml file and then set it in href as base64.

Check this thread: How to create a dynamic file + link for download in Javascript?

Community
  • 1
  • 1
Lukspa
  • 121
  • 1
  • 3