Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2002
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Any other way to update and edit an xmltree through html form inputs?

    Hi, is there any other way to update and edit an xmltree through html form inputs? Also, is there any way to display the xmltree directly to the page itself other than using alert() ?

    Coz the method i am using now is passing the xml tags as a string( Eg. var xstring ).. n i find this method is kinda not so dynamic
    ..

    this script is as follow:

    <html>
    <head>
    <script>

    var xstring = "<root><author></author><title></title><subtitle></subtitle><topic></topic><content></content><intro></intro><summary></summary></root>"

    // Load XML
    var xml = new ActiveXObject("Microsoft.XMLDOM")
    xml.async = false
    xml.loadXML(xstring)

    function getAuthor(){return getVal("author")}
    function getTitle(){return getVal("title")}
    function getSubTitle(){return getVal("subtitle")}
    function getTopic(){return getVal("topic")}
    function getContent(){return getVal("content")}
    function getIntro(){return getVal("intro")}
    function getSummary(){return getVal("summary")}




    function getVal(n){
    return xml.documentElement.getElementsByTagName(n).item(0).text;
    }

    function setAuthor(v){setVal("author",v)}
    function setTitle(v){setVal("title",v)}
    function setSubTitle(v){setVal("subtitle",v)}
    function setTopic(v){setVal("topic",v)}
    function setContent(v){setVal("content",v)}
    function setIntro(v){setVal("intro",v)}
    function setSummary(v){setVal("summary",v)}

    function setAll(v)
    {
    setAuthor(v)
    setTitle(v)
    setSubTitle(v)
    setTopic(v)
    setContent(v)
    setIntro(v)
    setSummary(v)

    }

    function setVal(n,v){
    xml.documentElement.getElementsByTagName(n).item(0).text = v;
    }

    function showXML(){
    alert(xml.xml)
    }

    function clearForm()
    {

    }

    </script>
    <head>

    <body>
    <form>
    <input type=text name=t0><br>
    <input type=button value="Set Author " onclick="setAuthor(this.form.t0.value)">
    <input type=button value="Get Author " onclick="alert(getAuthor())"><br><br>

    <input type=text name=t1><br>
    <input type=button value="Set Title" onclick="setTitle(this.form.t1.value)">
    <input type=button value="Get Title" onclick="alert(getTitle())"><br><br>

    <input type=text name=t2><br>
    <input type=button value=" Set Sub Title " onclick="setSubTitle(this.form.t2.value)">
    <input type=button value=" Get Sub Title " onclick="alert(getSubTitle())"><br><br>

    <input type=text name=t3><br>
    <input type=button value=" Set Topic " onclick="setTopic(this.form.t3.value)">
    <input type=button value=" Get Topic " onclick="alert(getTopic())"><br><br>

    <input type=text name=t4><br>
    <input type=button value=" Set Content " onclick="setContent(this.form.t4.value)">
    <input type=button value=" Get Content " onclick="alert(getContent())"><br><br>

    <input type=text name=t5><br>
    <input type=button value=" Set Intro " onclick="setIntro(this.form.t5.value)">
    <input type=button value=" Get Intro " onclick="alert(getIntro())"><br><br>

    <textarea name=t6 rows=10 cols=50></textarea><br>
    <input type=button value=" Set Summary " onclick="setSummary(this.form.t6.value)">
    <input type=button value=" Get Summary " onclick="alert(getSummary())"><br><br>
    <br>
    <input type=button value="Show XML " onclick="showXML()"><br>
    <input type=button value="Set All " onclick="setAll(this.form)"><br>
    <input type=reset value=Clear Form onclick="clearForm(this.form)">

    </form>
    </body>

    </html>

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,453
    Thanks
    1
    Thanked 21 Times in 19 Posts
    Sure. Study the Core Document Object Model, Level One (preferably Two), and implement an HTML form to do what it does.

    You'll love the DOM.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •