I asked the almost the same question before also, but i have not yet been able to figure out how to solve this issue of mine.
I have been assigned a project, in which I get a .xml file, which has field like, <TITLE>, <AUTHOR>,<ABSTRACT>, <COMMENT> and the <COMMENT> tag comes empty in the .xml, rest all the fields are already filled.
I have to parse this xml, and generate a report of it, i have already done this.
But the problem is, that i have a dropdown box for every COMMENT field in my report, and when i make change in the drop down box it shows the change on the client page but it does not update the xml file on the sever.
How can i do that. Is there anyway to insert, delete, update xml nodes?
Kindly help me with this.
I am using DOM to parse the xml file.
Also i read somewhere to XMLDocument class to make changes in the xml file. But if that is possible, can you please tell me about where can i find samples of xmlDocument used to make changes in xml file.
I appreciate you help.
Best
Zeeshan
The first place to start would be at w3schools. Once you can make changes to your document e.g.:-
var textNode = dom.createTextNode(myText);
dom.documentElement.selectSingleChild("COMMENT").appendChild(textNode);
You then need the servers assistance to accept the new XML document. You will need either a server script that accepts the XML document sent using a POST request or for the server to support PUT request to replace the original XML url. You will need the XmlHttpRequest object to acheive that.
XmlHttp on W3Schools can give you a beginners guide to doing that.
Related
I'm writing some html that links to a server to download a file. The location always remains the same, however, the file name gets updated.
Basically the link is like this:
http://www.somedomain.com/somedir/dir/filename_revA.pdf
The filename will often get revised ("filename_revB.pdf") for example. My goal would not having to change the html href code each time this happens.
TL;DR-- I want to be able to reference an url, ie: 'http://www.somedomain.com/somedir/dir/'
but not need the filename to fetch the file that is there after the last /.
Would RegEx (javascript) be best solution or a better method? Sorry if it's been asked I tried searching couldn't quite get what I wanted- requesting a URL WITHOUT the filename needed-while still fetching the actual file that's there. There's only one file that is there at all times, but perhaps to be safer using part of the name since only the last part changes?
edit- I don't have access to the server that hosts the file(s).
So I can't seem to find an straight answer to my problem.
What I want to do is load a JSON file that's located on a specified URL. It's a large complicated JSON file. Basically, I've been trying to use AJAX to 'get' the file all night long. I've used the $.getJSON Jquery shortcut too, without any luck. I believe the server isn't allowing for AJAX requests, but if I enter in the URL I can access the file without a problem.
My question is, is there any way I can get the file so I could use it in order to create this little mock up site that I need to create?
Is this possible?
I've tried looking for a way to just rip the text off of the URL and then just turning that into a JSON file so I could parse it, but I haven't found any relevant information on this tactic.
If you have any ideas, please let me know, thank you! :D
I am developing my first website. At this time i am generating a new html design that would be a ticket.
From my main page, i will load this html when the user clicks the "See ticket" button. This html has a table which is filled on document.ready with javascript. The data used is a JSON created in the main page.
I coded a working solution using localStorage. The problem is that the next step is to convert that HTML website to PDF and the software i am using does not work properly with localStorage, so i need to pass the JSON from main page to the ticket page. I can't neither use URL encoding cause string could be sometimes longer than 2000 characters and it is not productive.
So i thought that maybe i could do and $.get call from the ticket.html to index.html and get the needed JSON. Is this approach correct, or is there any better solution?
Regards
As suggested earlier comments, you need to use serverside code to accept post params and you need to do a ajax post to send the data. This is very good approach. I have one more idea for implementing this.
Let say you open ticket.html in a window.open. And have a JS function ( say GetValue) in index.html, that returns JSON . So you need to get JSON in ticket.html.
You need to define a JS function in ticket.html , using windown.opener.GetValue() , you can get JSON value.
Hope, i am in same direction, which you need. If not, please clarify.
Other way, would be use iFrame and use message communication to pass large data between them, you are interested in this, please read this - https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage
I have a new assignment which is wrinkling my brain. We create reports for auditing purposes, and save the file as HTML, and XML (to be used with XSLT). Those files are modified by few other guys, later on, and they don't have knowledge to edit XML files. So, I need help to make sure that changes are made on both XML and HTML files.
To explain it in less confusing manner, I want to allow user to modify HTML file, and the same changes should reflect in XML. I can use JavaScript to post form data, and modify XML on submit. Or I can attach ASP.Net script to do the same. But, right now, I am confused as to where to start, which scripting language will be a good idea, or if I should use form or hidden variables.
So, any help of any kind is appreciated here, as I am totally out of my depth here.
Edit:
So, I tried few things on my end. Turns out, we have a vb.net application, in which the HTML is displayed. So, it was easy to get the HTML data back to vb.net. Now, I have a vb.net String "strHTMLData" which contains the updated value for an HTML text field.
But, I can't figure out how to write this string to an existing node in XML. I can write it in a new file, just fine. But, finding the existing node and updating the value is getting too tricky.
For example:
Dim reader As XmlTextReader = New XmlTextReader("Test.Xml")
Dim writer As XmlTextWriter = New XmlTextWriter("Test2.Xml", System.Text.Encoding.Unicode)
writer.WriteNode(reader, True)
This works fine, and the writer creates a Test2.Xml as an exact copy of Test.Xml.
Do While (reader.Read())
Select Case reader.NodeType
Case XmlNodeType.Element 'Display beginning of element.
'Code to change node element
Case XmlNodeType.Text 'Display the text in each element.
'Code to change node value
If reader.Name = "Summary" Then
writer.WriteValue("Edited Summary")
End If
End Select
Loop
This on the other hand, doesn't work. There is no error at all, but node "Summary" doesn't get updated.
Changes take place in the page, you post changes, fetch xml and update it. Now what you have against that.
I have a javascript routine that dynamically creates an HTML page, complete with it's own head and script tags.
If I take the contents of the string and save it to a file, and view the file in a browser, all is well, but if I try document.write(newHTML), it doesn't behave the same. The javascript in the header of the dynamic newHTML is quite complicated, and I cannot include it here... But please believe me that it works great if I save it to a file, but not if I try to replace the current page with it using document.write. What possible pitfalls could be contributing to this that I'm not considering? Do I possibly need to delete the existing script tags in the existing header first? Do I need to manually re-call onLoad??
Again, it works great when the string is saved to, for example, 'sample.html' and browsed to, but if I set var Samp="[REAL HTML HERE]"; and then say document.write(Samp); document.close(); the javascript routines are not executing correctly.
Any hints as to what I could be missing?
Is there another/better way to dynamically replace the content of the page, other than document.write?
Could I somehow redirect to the new page despite the fact that doesn't exist on disk or on a server, but is only in a string in memory? I would hate to have to upload the entire file to my server simply to re-download again it to view it.
How can I, using javascript, replace the current content of the current page with entirely new content including complex client-side javascripting, dynamically, and always get exactly the same result as if I saved the string to the server as an html file and redirected to it?
How can I 'redirect' to an HTML file that only exists as a client-side string?
You can do this:
var win=window.open("") //open new window and write to it
var html = generate_html();
win.document.write(html)
win.document.close();
Maybe eval() function would help here? It's hard to give ansver without seeing the code.
Never tried this, but i think it should be possible. Some thoughts on what might make it work:
Make sure the document containing your js is sent with the correct headers / mimetype / doctype
Serve the javascript in a valid way, for example by sending a w3c valid page containing the script tag.
Maybe then it works. If not, try to erase the current html before writing the new one.
Also, it might be helpful to look how others managed to accomplish this task. If i remind it correctly, the google page is also essentially a short html page with a bunch of js.