Forum Moderators: open
On our website, I use an XML 'database' to store a number of news items. They consist of the title, the date, the page to be linked to, a description (content element) and the element 'style_identifier' , which is used to change the id attribute if it is the last item in the list (because different markup needed here).
Via ASP and XSLT, the corresponding block of code is written on the pages, forming a small news block with links to the latest news. Also, if the element 'onhomepage' says 'yes', the news will also be placed there, and the opposite for 'no'. The XML code is posted below.
Now what I want to implement, is an ASP-page with a form, which people can then use to post a news item. From this asp-page/form, the corresponding lines should be written ('appended') to the xml file containing all the news.
Question 1: How to best go about this?
Question 2: How can I best secure this? I mean of course it's not the intention that everyone can use this, so can I password-protect it or protect it in some other way?
Darkelve
<news><lastupdate>9 december 2004</lastupdate>
<article id="1">
<onhomepage>yes</onhomepage>
<title>de nieuwslijn</title>
<date>25 February 2005</date>
<internetaddress>http://www.example/page.html</internetaddress>
<content>Wijziging dienstregeling tijdens werken aan Sint-Lievenspoortbruggen en langs tracé tramlijn 4<content>
<style_identifier>newsitem</style_identifier>
</article>
<article id="2">
<onhomepage>no</ophomepage>
<title>de nieuwslijn</title>
<date>17 Januari 2004</date>
<internetaddress>http://www.example.com/page2.html</internetaddress>
<content>Nieuwe lijnnummers in West-Vlaanderen</content>
<style_identifier>newsitem</style_identifier>
</article>
</news>
[edited by: tedster at 5:59 pm (utc) on Mar. 7, 2005]
[edit reason] use example.com [/edit]
Suggestion #1:
First, set up a File Scripting Object with an append option in your ASP. Of course, you will append to the XML file. You ASP file will need to temporarily strip off the end tag of your XML root element </news>
Then, you can set up a temporary variable to create the XML with the data from the form and just create raw XML nodes and write the variable to your text file.
Suggestion #2:
Use the DOM. Load your XML file into ASP file using Server.CreateObject("Microsoft.XMLDOM") - Then, use the createELement or CreateNode function to create the new XML node and write it all to the XML file using FSO in your ASP.
Bruce
option 2) (the DOM?) is actually what I use to transform the XML into the appropriate chunk of xhtml (through use of an XSL stylesheet):
<%
'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("myscript.xml"))'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("mysheet.xsl"))
'Transform file
Response.Write(xml.transformNode(xsl))
%>
So with the funtions 'createELement' or 'CreateNode' in ASP I can create the appropriate element, and then substitute the value of the XML element by the form variable? Does anyone know of a tutorial that handles this?
I only know a bit of ASP (Vbscript) programming, though happy to learn more.