ASP and XML problem

Discussion in 'ASP General' started by w@m, Jun 18, 2006.

  1. w@m

    w@m Guest

    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.
     
    w@m, Jun 18, 2006
    #1
    1. Advertising

  2. w@m wrote:
    > 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"
     
    Bob Barrows [MVP], Jun 18, 2006
    #2
    1. Advertising

  3. w@m

    w@m Guest

    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 [MVP]" <> schreef in bericht
    news:...
    > w@m wrote:
    >> 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"
    >
     
    w@m, Jun 18, 2006
    #3
  4. w@m wrote:
    > 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)



    --
    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"
     
    Bob Barrows [MVP], Jun 18, 2006
    #4
  5. w@m

    w@m Guest

    Hi Bob,

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

    Regards,

    W.

    "Bob Barrows [MVP]" <> schreef in bericht
    news:...
    > w@m wrote:
    >> 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)
    >
    >
    >
    > --
    > 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"
    >
     
    w@m, Jun 19, 2006
    #5
  6. w@m wrote:
    > 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 ...


    >> <%
    >> 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) <<<-------------delete this!
    >> 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)
    >>
    >>
    >>
    >> --
    >> 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"


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Jun 19, 2006
    #6
  7. w@m

    w@m Guest

    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.

    "Bob Barrows [MVP]" <> schreef in bericht
    news:...
    > w@m wrote:
    >> 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 ...
    >
    >
    >>> <%
    >>> 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) <<<-------------delete this!
    >>> 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)
    >>>
    >>>
    >>>
    >>> --
    >>> 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"

    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
     
    w@m, Jun 20, 2006
    #7
  8. w@m wrote:
    > 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:

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


    should be

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



    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Jun 20, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page