ASP and XML problem

W

w@m

Hi,

I'm trying to use ASP to write XML documents form input from a HTML form.
I have to write some tags like this:


<creation audience="internal">Written in
<date>[input from form: yyyy]</date>by using guideline
<title>[input from form]</title>and reviewed by
<employee>[input from form]</employee>on
<date>[input from form: mm/dd/yy]</date>
</creation>

It's the standard text that has to go between the tags (from the second one
onwards) that's giving me a headache.
I've tried to solve this by the following code, but the 'Response.Write's'
won't do the trick:


Set objChildCreation = objDom.createElement("creation")
objChildReviewdesc.appendChild objChildCreation
objChildCreation.setAttributeNode objattCreationAudience
objattCreationAudience.Text="internal"
objChildCreation.Text = "Written in"

Set objChildCreation1Date = objDom.createElement("date")
objChildCreation.appendChild objChildCreation1Date
objChildCreation1Date.Text = Request.Form("firstdate")

Response.Write (" by using guideline ")

Set objChildCreationTitle = objDom.createElement("title")
objChildCreation.appendChild objChildCreationTitle
objChildCreationTitle.Text=Request.Form("title")

Response.Write (" and reviewed by ")

Set objChildCreationEmployee = objDom.createElement("employee")
objChildCreation.appendChild objChildCreationEmployee
objChildCreationEmployee.Text=Request.Form("employee")

Response.Write (" on ")

Set objChildCreation2Date = objDom.createElement("date")
objChildCreation.appendChild objChildCreation2Date
objChildCreation2Date.Text = Request.Form("seconddate")

Any help would be appreciated,

TIA

W.
 
B

Bob Barrows [MVP]

w@m said:
Hi,

I'm trying to use ASP to write XML documents form input from a HTML
form. I have to write some tags like this:


<creation audience="internal">Written in
<date>[input from form: yyyy]</date>by using guideline
<title>[input from form]</title>and reviewed by
<employee>[input from form]</employee>on
<date>[input from form: mm/dd/yy]</date>
</creation>

It's the standard text that has to go between the tags (from the
second one onwards) that's giving me a headache.
I've tried to solve this by the following code, but the
'Response.Write's' won't do the trick:
You need to use either the CreateNode method -
http://msdn.microsoft.com/library/en-us/xmlsdk/html/5bba501f-65c9-4d30-a555-afb325a6fc84.asp
or, more simply, the createTextNode method -
http://msdn.microsoft.com/library/en-us/xmlsdk/html/c5d24b30-8522-4586-9287-93971eb664fe.asp
Set objChildCreation = objDom.createElement("creation")
objChildReviewdesc.appendChild objChildCreation
objChildCreation.setAttributeNode objattCreationAudience
objattCreationAudience.Text="internal"

setAttribute is simpler -
http://msdn.microsoft.com/library/en-us/xmlsdk/html/1defea0d-6b6e-48da-80b6-3a75a49123bb.asp

objChildCreation.setAttribute "audience", "internal"
objChildCreation.Text = "Written in"

Set objChildCreation1Date = objDom.createElement("date")
objChildCreation.appendChild objChildCreation1Date
objChildCreation1Date.Text = Request.Form("firstdate")

You really should validate user inputs ...
Response.Write (" by using guideline ")

Set objTextNode = objDom.createTextNode(" by using guideline ")
objChildCreation.appendChild objTextNode
 
W

w@m

Hi Bob,

Thanks a lot, that works just fine; also thanks for pointing me at a more
efficient way of dealing with attributes; but what do you mean by "you
really should validate user inputs"?

In addition to this: is it possible to make 'if-then-else' constructions
when generating xml documents like this? I mean: I also have to tag like
this:

<langusage>This finding aid is in
<language langcode="dut" scriptcode="latn">Dutch</language>
</langusage>

At the moment I use three comboboxes on the input form to generate the two
attribute values and the tag value itself, but off course it would be much
easier to just ask for the language (Dutch or English or French) and
depending on this user input fill the values of the attributes accordingly.

Again: thanks in advance for any assistence,

W.


Bob Barrows said:
w@m said:
Hi,

I'm trying to use ASP to write XML documents form input from a HTML
form. I have to write some tags like this:


<creation audience="internal">Written in
<date>[input from form: yyyy]</date>by using guideline
<title>[input from form]</title>and reviewed by
<employee>[input from form]</employee>on
<date>[input from form: mm/dd/yy]</date>
</creation>

It's the standard text that has to go between the tags (from the
second one onwards) that's giving me a headache.
I've tried to solve this by the following code, but the
'Response.Write's' won't do the trick:
You need to use either the CreateNode method -
http://msdn.microsoft.com/library/en-us/xmlsdk/html/5bba501f-65c9-4d30-a555-afb325a6fc84.asp
or, more simply, the createTextNode method -
http://msdn.microsoft.com/library/en-us/xmlsdk/html/c5d24b30-8522-4586-9287-93971eb664fe.asp
Set objChildCreation = objDom.createElement("creation")
objChildReviewdesc.appendChild objChildCreation
objChildCreation.setAttributeNode objattCreationAudience
objattCreationAudience.Text="internal"

setAttribute is simpler -
http://msdn.microsoft.com/library/en-us/xmlsdk/html/1defea0d-6b6e-48da-80b6-3a75a49123bb.asp

objChildCreation.setAttribute "audience", "internal"
objChildCreation.Text = "Written in"

Set objChildCreation1Date = objDom.createElement("date")
objChildCreation.appendChild objChildCreation1Date
objChildCreation1Date.Text = Request.Form("firstdate")

You really should validate user inputs ...
Response.Write (" by using guideline ")

Set objTextNode = objDom.createTextNode(" by using guideline ")
objChildCreation.appendChild objTextNode

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
 
B

Bob Barrows [MVP]

w@m said:
Hi Bob,

Thanks a lot, that works just fine; also thanks for pointing me at a
more efficient way of dealing with attributes; but what do you mean by
"you
really should validate user inputs"?

Never trust user inputs. Hackers love sites where no server-side validation
of inputs is done. Never assume that client-side validation was even done.
Never assume that your form controls were even used.

You should make sure the inputs contain what they are supposed to contain,
and only what they are supposed to contain.
In addition to this: is it possible to make 'if-then-else'
constructions when generating xml documents like this? I mean: I also have
to tag
like this:

<langusage>This finding aid is in
<language langcode="dut" scriptcode="latn">Dutch</language>
</langusage>

At the moment I use three comboboxes on the input form to generate
the two attribute values and the tag value itself, but off course it would
be
much easier to just ask for the language (Dutch or English or French) and
depending on this user input fill the values of the attributes
accordingly.

Of course. Why wouldn't it be possible? However, this sounds like a good
place for an array, rather than if ... else:


<select name="lang">
<option value=0>Dutch
<option value=1>English
<option value=2>French
</select>


<%
dim arLang(2,2)
arLang(0,0)="dut"
arLang(1,0)="latn"
arLang(2,0)="Dutch"
dim arLang(2,2)
arLang(0,1)="eng"
arLang(1,1)="latn"
arLang(2,1)="English"
dim arLang(2,2)
arLang(0,2)="fre"
arLang(1,2)="latn"
arLang(2,2)="French"

dim lang
lang=cint(request.form("lang"))
....

objLangNode.setAttribute "langcode".arLang(0,lang)
objLangNode.setAttribute "scriptcode".arLang(1,lang)
objLangNode.Text=arLang(2,lang)
 
W

w@m

Hi Bob,

I tried this, but it returns an error: arLang is defined more than once.

Regards,

W.
 
B

Bob Barrows [MVP]

w@m said:
Hi Bob,

I tried this, but it returns an error: arLang is defined more than
once.

Yep. I goofed. Get rid of the second "dim arlang(2,2)" statement. I was
doing some copying and pasting for this and objviously copied one line
too many ...

 
W

w@m

Hi Bob,

Sorry, but that doesn't work either, so I decided to give an
if..then..else-construction a try and that works fine.

Regards,

W.
 
B

Bob Barrows [MVP]

w@m said:
Hi Bob,

Sorry, but that doesn't work either,

What was the symptom?? "doesn't work" doesn't work.
so I decided to give an
if..then..else-construction a try and that works fine.
It's your app ...

I just spotted another problem. I mistakenly typed periods where i
should have typed commas:

should be

objLangNode.setAttribute "langcode",arLang(0,lang)
objLangNode.setAttribute "scriptcode",arLang(1,lang)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

classi asp 0
asp vbscript textbox paste from word problem 5
ASP/Java 3
Problem Parsing XML into ASP 3
XML and ASP 1
New to ASP need help 1
mail program in asp 0
Java script on classic ASP page 6

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top