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.
Related
My limited experience in web development as a self-taught led me to hit a wall while trying to figure out how to deal with this problem.
I need a form (map_settings.php) where the user should enter some inputs. Those inputs must be saved in a database table (MAPS) and then used to create the final HTML file (e.g. map1.html) for that specific user/inputs.
I know how to deal with using forms and saving submitted data to a database.
What is completely obscure to me is how can I use those inputs to automatically generate the final HTML.
My idea is to have a template HTML (template.html) and each time a user saves new settings via the form, I copy the template and replace some variables inside it with the actual data the user has input in the form.
If this might matter, the variables I need to replace in the template are also JavaScript variables within a <script> tag.
Can anybody help me suggesting one viable way to do this? I am mostly using JavaScript and PHP, without frameworks. I've also red about JavaScript templating engines, but I sincerely did not get if those are useful to me in my case.
Anyway, here is an illustration of what I would need to do, to hopefully clarify better my point.
Creating a static HTML file per user is not the way to go. Instead just have a PHP script like mapdisplay.php or similar.
Make the script so that if you type mapdisplay.php?map=1 in the browser then it will read the map ID, get the relevant settings from the database for the map in question and then generate some HTML to display them - of course you can have most of the HTML ready made like a template, and just use PHP to fill in the details from the database. This idea of getting data on the fly when requested, and plugging it into some HTML is how most web applications work.
If you create a static HTML for each user it quickly becomes unmanageable with a large number of users, plus it's hard to introduce changes or improvements to the template because instead of just updating one script file, you have to back and re-do every existing page. There are other disadvantages to your approach too, but I won't continue here - you get the idea I hope.
If I were you I'll make that in this way:
Don't use template.html
Don't get data from database to new file, but from form
Make database test before make file
To make template use
$template_text = "text...text...html...text...".$php_varible."text...text...html...text";
For other things about php see w3schools
How could I save changes made to "contentEditable" sections back to original HTML file. Is this even possible?
I need to create a single html file that has sections for user changes. Using their web browser, I would like the user to be able to "save" the changes so that the original HTML file would actually be updated. This file might be stored on the user's PC, it might end up hosted on a server. Wherever it is, it needs to write the changes back to the HTML file.
EDIT:
Maybe some more details will help. I am looking to create a dynamic character sheet for all the RPGs I GM. I have used doc sharing services, but the interactive and dynamic nature of HTML+javascript offer more of what I need. Designing the file is easy enough. I just want players to open it in a web browser (even if stored on their desktop), make notes and edits, and then click a "save your character" button that will write the elements they changed back to the original HTML file. If there's no conceivable way to do this, that ok, I would just like some definitive info.
The file lives on a server somewhere, and the browser retrieves the files from that server, after which you can mess with contentEditable content, so to get the changes propagated to the original files, you'll need at least two things:
an event handler on the element(s) that have the contentEditable property, so that you can hook into their content modifications.
an API on the server that lets you tell it to update file X with content Y
The basic approach would be:
load HTML from server in browser
click on element with contentEditable property and start editing
finish editing, and have the element's javascript handler kick in (see https://stackoverflow.com/a/14043919/740553 for how to do that).
take the current URL, and the route to the element you just changed, and its new content, and then POST that to the server. This requires that:
the server is running an accepting route that listens for POST data on some route like ..../changepage (without accepting input from just anyone, of course), and that:
can take a POSTed filename, element path, and content string, opens up that file, finds the element in question, replaces its content, and packs it back up into a new file with the same filename as before.
This is, to say the least, extremely fragile and prone to bugs as well as abuse. There are better ways to do this, and pretty much all of them rely on having a content server, and a page that loads in content for very specifically editable elements from your content server, so that showing, editing, and saving content all happens to "one thing" instead of to elements that need to resolved in .html files based on their element path.
Or, making things even easier, using something like React to make most of that virtually instant. Although, of course, you'll still be left with writing your server such that it can serve up content, and accept modification requests.
Unfortunately for you, what you want to do is actually extremely hard to do well, as well as securely.
I'm working on an code editor using blockly, and my page currently has tabs for switching between Block View and Code View, kinda like some WYSIWYG editors. Now, Blockly already has plenty of stuff for going from blocks to code, and I've gotten 99% of the parts done so that I can go from code to blocks (it involves building up a bunch of block xml). My call to go from code view to block view looks like this:
var xml = Blockly.Xml.textToDom(self.xmlGenerated());
Blockly.mainWorkspace.clear();
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace, xml);
The problem is, no matter what id attributes I set in my xml nodes, blockly overrides them when I try to read the block xml later. It seems they constantly increment, even though I'm clearing the workspace. This causes a problem for my auto-save feature since that means each time I go from code to blocks my xml is changing, and therefore my code is changing (the generated code is a graph structure that also uses the id fields to identity each node in the graph).
So, my question is, does anyone know how to prevent Blockly from overriding the node id I send, or is there a way to "reset" the node ids?
I asked a very similar question in the Blockly Google group and Neil added a new data XML tag for storing persistent data. Maybe you can put your ID there? From reading the code seems like the id attribute was meant for internal use so it may be unreliable to reuse it.
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.
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.