ASP and XML problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • w@m

    ASP and XML problem

    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="inter nal">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 objChildCreatio n = objDom.createEl ement("creation ")
    objChildReviewd esc.appendChild objChildCreatio n
    objChildCreatio n.setAttributeN ode objattCreationA udience
    objattCreationA udience.Text="i nternal"
    objChildCreatio n.Text = "Written in"

    Set objChildCreatio n1Date = objDom.createEl ement("date")
    objChildCreatio n.appendChild objChildCreatio n1Date
    objChildCreatio n1Date.Text = Request.Form("f irstdate")

    Response.Write (" by using guideline ")

    Set objChildCreatio nTitle = objDom.createEl ement("title")
    objChildCreatio n.appendChild objChildCreatio nTitle
    objChildCreatio nTitle.Text=Req uest.Form("titl e")

    Response.Write (" and reviewed by ")

    Set objChildCreatio nEmployee = objDom.createEl ement("employee ")
    objChildCreatio n.appendChild objChildCreatio nEmployee
    objChildCreatio nEmployee.Text= Request.Form("e mployee")

    Response.Write (" on ")

    Set objChildCreatio n2Date = objDom.createEl ement("date")
    objChildCreatio n.appendChild objChildCreatio n2Date
    objChildCreatio n2Date.Text = Request.Form("s econddate")

    Any help would be appreciated,

    TIA

    W.



  • Bob Barrows [MVP]

    #2
    Re: ASP and XML problem

    w@m wrote:[color=blue]
    > 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="inter nal">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:
    >[/color]
    You need to use either the CreateNode method -

    or, more simply, the createTextNode method -
    http://msdn.microsoft.com/library/en...971eb664fe.asp[color=blue]
    >
    > Set objChildCreatio n = objDom.createEl ement("creation ")
    > objChildReviewd esc.appendChild objChildCreatio n
    > objChildCreatio n.setAttributeN ode objattCreationA udience
    > objattCreationA udience.Text="i nternal"[/color]

    setAttribute is simpler -


    objChildCreatio n.setAttribute "audience", "internal"
    [color=blue]
    > objChildCreatio n.Text = "Written in"
    >
    > Set objChildCreatio n1Date = objDom.createEl ement("date")
    > objChildCreatio n.appendChild objChildCreatio n1Date
    > objChildCreatio n1Date.Text = Request.Form("f irstdate")[/color]

    You really should validate user inputs ...
    [color=blue]
    >
    > Response.Write (" by using guideline ")[/color]

    Set objTextNode = objDom.createTe xtNode(" by using guideline ")
    objChildCreatio n.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"


    Comment

    • w@m

      #3
      Re: ASP and XML problem

      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>Th is finding aid is in
      <language langcode="dut" scriptcode="lat n">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]" <reb01501@NOyah oo.SPAMcom> schreef in bericht
      news:ee1f06tkGH A.1204@TK2MSFTN GP02.phx.gbl...[color=blue]
      > w@m wrote:[color=green]
      >> 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="inter nal">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:
      >>[/color]
      > You need to use either the CreateNode method -
      > http://msdn.microsoft.com/library/en...b325a6fc84.asp
      > or, more simply, the createTextNode method -
      > http://msdn.microsoft.com/library/en...971eb664fe.asp[color=green]
      >>
      >> Set objChildCreatio n = objDom.createEl ement("creation ")
      >> objChildReviewd esc.appendChild objChildCreatio n
      >> objChildCreatio n.setAttributeN ode objattCreationA udience
      >> objattCreationA udience.Text="i nternal"[/color]
      >
      > setAttribute is simpler -
      > http://msdn.microsoft.com/library/en...75a49123bb.asp
      >
      > objChildCreatio n.setAttribute "audience", "internal"
      >[color=green]
      >> objChildCreatio n.Text = "Written in"
      >>
      >> Set objChildCreatio n1Date = objDom.createEl ement("date")
      >> objChildCreatio n.appendChild objChildCreatio n1Date
      >> objChildCreatio n1Date.Text = Request.Form("f irstdate")[/color]
      >
      > You really should validate user inputs ...
      >[color=green]
      >>
      >> Response.Write (" by using guideline ")[/color]
      >
      > Set objTextNode = objDom.createTe xtNode(" by using guideline ")
      > objChildCreatio n.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"
      >[/color]


      Comment

      • Bob Barrows [MVP]

        #4
        Re: ASP and XML problem

        w@m wrote:[color=blue]
        > 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"?[/color]

        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.
        [color=blue]
        >
        > 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>Th is finding aid is in
        > <language langcode="dut" scriptcode="lat n">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.[/color]

        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)="du t"
        arLang(1,0)="la tn"
        arLang(2,0)="Du tch"
        dim arLang(2,2)
        arLang(0,1)="en g"
        arLang(1,1)="la tn"
        arLang(2,1)="En glish"
        dim arLang(2,2)
        arLang(0,2)="fr e"
        arLang(1,2)="la tn"
        arLang(2,2)="Fr ench"

        dim lang
        lang=cint(reque st.form("lang") )
        ....

        objLangNode.set Attribute "langcode".arLa ng(0,lang)
        objLangNode.set Attribute "scriptcode".ar Lang(1,lang)
        objLangNode.Tex t=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"


        Comment

        • w@m

          #5
          Re: ASP and XML problem

          Hi Bob,

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

          Regards,

          W.

          "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> schreef in bericht
          news:ugewx0wkGH A.836@TK2MSFTNG P02.phx.gbl...[color=blue]
          > w@m wrote:[color=green]
          >> 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"?[/color]
          >
          > 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.
          >[color=green]
          >>
          >> 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>Th is finding aid is in
          >> <language langcode="dut" scriptcode="lat n">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.[/color]
          >
          > 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)="du t"
          > arLang(1,0)="la tn"
          > arLang(2,0)="Du tch"
          > dim arLang(2,2)
          > arLang(0,1)="en g"
          > arLang(1,1)="la tn"
          > arLang(2,1)="En glish"
          > dim arLang(2,2)
          > arLang(0,2)="fr e"
          > arLang(1,2)="la tn"
          > arLang(2,2)="Fr ench"
          >
          > dim lang
          > lang=cint(reque st.form("lang") )
          > ...
          >
          > objLangNode.set Attribute "langcode".arLa ng(0,lang)
          > objLangNode.set Attribute "scriptcode".ar Lang(1,lang)
          > objLangNode.Tex t=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"
          >[/color]


          Comment

          • Bob Barrows [MVP]

            #6
            Re: ASP and XML problem

            w@m wrote:[color=blue]
            > Hi Bob,
            >
            > I tried this, but it returns an error: arLang is defined more than
            > once.
            >[/color]

            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 ...

            [color=blue][color=green]
            >> <%
            >> dim arLang(2,2)
            >> arLang(0,0)="du t"
            >> arLang(1,0)="la tn"
            >> arLang(2,0)="Du tch"
            >> dim arLang(2,2)
            >> arLang(0,1)="en g"
            >> arLang(1,1)="la tn"
            >> arLang(2,1)="En glish"
            >> dim arLang(2,2) <<<-------------delete this!
            >> arLang(0,2)="fr e"
            >> arLang(1,2)="la tn"
            >> arLang(2,2)="Fr ench"
            >>
            >> dim lang
            >> lang=cint(reque st.form("lang") )
            >> ...
            >>
            >> objLangNode.set Attribute "langcode".arLa ng(0,lang)
            >> objLangNode.set Attribute "scriptcode".ar Lang(1,lang)
            >> objLangNode.Tex t=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"[/color][/color]

            --
            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.


            Comment

            • w@m

              #7
              Re: ASP and XML problem

              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]" <reb01501@NOyah oo.SPAMcom> schreef in bericht
              news:ezkZI19kGH A.4888@TK2MSFTN GP02.phx.gbl...[color=blue]
              > w@m wrote:[color=green]
              >> Hi Bob,
              >>
              >> I tried this, but it returns an error: arLang is defined more than
              >> once.
              >>[/color]
              >
              > 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 ...
              >
              >[color=green][color=darkred]
              >>> <%
              >>> dim arLang(2,2)
              >>> arLang(0,0)="du t"
              >>> arLang(1,0)="la tn"
              >>> arLang(2,0)="Du tch"
              >>> dim arLang(2,2)
              >>> arLang(0,1)="en g"
              >>> arLang(1,1)="la tn"
              >>> arLang(2,1)="En glish"
              >>> dim arLang(2,2) <<<-------------delete this!
              >>> arLang(0,2)="fr e"
              >>> arLang(1,2)="la tn"
              >>> arLang(2,2)="Fr ench"
              >>>
              >>> dim lang
              >>> lang=cint(reque st.form("lang") )
              >>> ...
              >>>
              >>> objLangNode.set Attribute "langcode".arLa ng(0,lang)
              >>> objLangNode.set Attribute "scriptcode".ar Lang(1,lang)
              >>> objLangNode.Tex t=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"[/color][/color]
              >
              > --
              > 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.
              >
              >[/color]


              Comment

              • Bob Barrows [MVP]

                #8
                Re: ASP and XML problem

                w@m wrote:[color=blue]
                > Hi Bob,
                >
                > Sorry, but that doesn't work either,[/color]

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

                I just spotted another problem. I mistakenly typed periods where i
                should have typed commas:
                [color=blue][color=green]
                >> objLangNode.set Attribute "langcode".arLa ng(0,lang)
                >> objLangNode.set Attribute "scriptcode".ar Lang(1,lang)[/color][/color]

                should be

                objLangNode.set Attribute "langcode",arLa ng(0,lang)
                objLangNode.set Attribute "scriptcode",ar Lang(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.


                Comment

                Working...