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 13 of 13
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question XML help (noob here)

    (based from the tutorial in w3schools.com)
    let's say the user created this xml script
    Code:
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <body>Don't forget me this weekend!</body>
    </note>
    and it should output this

    and then let's say the user decided to add an element later on in the script like
    Code:
    <note>
    <date>2008-01-10</date>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    </note>
    w3cshool said, the application will not crash because it can still detect the <to>, <from>, and <body> elements in the XML document and produce the same output.

    so my question now is..what's gonna happen with the <date> ? where did it go ?
    why was it not detected at all ? (im new to this thing)

  • #2
    Regular Coder Samhain13's Avatar
    Join Date
    Aug 2008
    Location
    Pilipinas
    Posts
    169
    Thanks
    4
    Thanked 18 Times in 18 Posts
    A link to the tutorial would be helpful because we need to find out how what script handles which output.

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question hello

    Quote Originally Posted by Samhain13 View Post
    A link to the tutorial would be helpful because we need to find out how what script handles which output.
    here is a link to the tutorial sir.. i hope you can help me configure this out..their explanation is not that clear for a slow learner to understand

  • #4
    Regular Coder Samhain13's Avatar
    Join Date
    Aug 2008
    Location
    Pilipinas
    Posts
    169
    Thanks
    4
    Thanked 18 Times in 18 Posts
    Are you using this tutorial? http://w3schools.com/xml/xml_dom.asp

    In your first post, you mention changing the XML file by adding an "date" element. But it doesn't show anywhere, right? That's because you'd also need to change the javascript a bit so that it knows what to do with the new "date" element.

    You'll need to add this to the javascript:
    Code:
    document.getElementById("date").innerHTML=
    xmlDoc.getElementsByTagName("date")[0].childNodes[0].nodeValue;
    And then add something like this to the HTML:
    Code:
    <p>Date <span id="date"></span></p>
    Rough explanation:
    The javascript part, in plain English says "get the node value of the date element of xmlDoc (your XML file) and put it into the span that's identified as 'date'".

    So, aside from editing the XML, the javascript also needs to know what to do with the new element AND in the HTML, there needs to be a place where the javascript can throw in what it finds. If there's no <span id="date"></span>, javascript will have no where to put what it found in the new <date></date> element. That's why you didn't see anything happening.

    Sorry if that was confusing, but try it out and hopefully you'll see what I mean. Cheers!
    Last edited by Samhain13; 09-03-2008 at 01:38 AM.

  • #5
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts
    i don't understand..i just plunge to xml directly without learning javascript.. basic xml though

  • #6
    Regular Coder Samhain13's Avatar
    Join Date
    Aug 2008
    Location
    Pilipinas
    Posts
    169
    Thanks
    4
    Thanked 18 Times in 18 Posts
    Alright. Let's try again...

    In that tutorial, there are basically 3 things involved: XML, Javascript and HTML.
    XML is where you put your stuff.
    Javascript reads the XML and gets your stuff from it.
    HTML is where Javascript puts the stuff that it got from your XML.

    So, simply changing the XML isn't going to change what you see in your browser because what's shown in the browser is only the HTML. We have to write additional instructions in the Javascript too. And we have to prepare the HTML in a certain way so that the Javascript can follow our new instructions.

    If you follow my previous post, you'll get something like this new file (the changes I wrote about are in bold letters):
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function parseXML()
    {
    try //Internet Explorer
      {
      xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
      }
    catch(e)
      {
      try //Firefox, Mozilla, Opera, etc.
        {
        xmlDoc=document.implementation.createDocument("","",null);
        }
      catch(e)
        {
        alert(e.message);
        return;
        }
      }
    xmlDoc.async=false;
    xmlDoc.load("note.xml");
    
    document.getElementById("date").innerHTML=
    xmlDoc.getElementsByTagName("date")[0].childNodes[0].nodeValue;
    document.getElementById("to").innerHTML=
    xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
    document.getElementById("from").innerHTML=
    xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
    document.getElementById("message").innerHTML=
    xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
    }
    </script>
    </head>
    
    <body onload="parseXML()">
    <h1>W3Schools Internal Note</h1>
    <p>Date: <span id="date"></span></p>
    <p><b>To:</b> <span id="to"></span><br />
    <b>From:</b> <span id="from"></span><br />
    <b>Message:</b> <span id="message"></span>
    </p>
    </body>
    </html>
    You can try this with your XML file that has that new "date" element. But you should know that if you remove the date element or add another new element, this will no longer work.

    Of course, as you progress, you'll find that there's a cleaner way of writing the code that I posted. But you'll have to make do with this for now.

  • #7
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Unhappy lol

    geeeezzz.... duduguin ang ilong ko nito... things in my head all mixed up now..am stucked with php coding with xml extension while i don't know all about xml..now here comes javascripting LOL

  • #8
    Regular Coder Samhain13's Avatar
    Join Date
    Aug 2008
    Location
    Pilipinas
    Posts
    169
    Thanks
    4
    Thanked 18 Times in 18 Posts
    Hah! Pinoy ka din pala! :P

    Take it easy, learn just one thing at a time. The thing you're trying to learn has AJAX written all over it. And AJAX is not really for beginners. Practice XML and HTML first, they're not so unlike each other anyway. Then dive into Javascript. Hehehe!

  • #9
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts
    nyahaha..salamat sa tip boss .... ok boss ill try to learn xml and html combination first..

  • #10
    Regular Coder
    Join Date
    Jul 2008
    Posts
    195
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Quote Originally Posted by capt_nemo777 View Post
    nyahaha..salamat sa tip boss .... ok boss ill try to learn xml and html combination first..
    What are you trying to accomplish anyways?

    And you don't learn XML. There XML can't do anything. It's just tags with data. YOU make it up. All you need is this:
    <tag name>Data</same tag name>

    That is XML.

    The issue you are having is displaying the data.
    -MacWiz1220
    Science fiction does not remain fiction for long. And certainly not on the Internet.
    -Vinton Cerf: Chief Internet Evangelist for Google and co-creator of the TCP/IP Internet Protocol Suite

  • #11
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Xml

    XML stands for EXtensible Markup Language and it was designed to transport and store data.Xml is the most common tool for data transmissions between all sorts of applications, and becomes more and more popular in the area of storing and describing information.If you need to display dynamic data in your HTML document, it will take a lot of work to edit the HTML each time the data changes.With XML, data can be stored in separate XML files.
    --------------------------------------
    gillberk

    ETHICAL SEO

  • #12
    Banned
    Join Date
    Sep 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi freinds, please help me to display page number in XMl.
    Last edited by masmedia; 09-05-2013 at 03:08 PM.

  • #13
    Regular Coder Samhain13's Avatar
    Join Date
    Aug 2008
    Location
    Pilipinas
    Posts
    169
    Thanks
    4
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by macwiz View Post
    And you don't learn XML. There XML can't do anything. It's just tags with data. YOU make it up. All you need is this:
    <tag name>Data</same tag name>

    That is XML.
    Just for kicks. Your example is wrong and that is NOT XML.

    This would make it right though:

    Code:
    <tag name="attribute value">Data</tag>
    Hence, you do have to learn XML if you want to use it; because even if in many case, you'll be inventing tag names anyway, there are rules that need to be followed.


  •  

    Posting Permissions

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