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.
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,096
    Thanks
    23
    Thanked 594 Times in 593 Posts
    How does the parser know which is meant to be a decimal, which a string, which a date, etc.
    As has been said above, they are all text. If you can tell me how you can find the difference between them using the schema please let me know. I don't think the schema tells you if something is a time, a number, etc..

    When I started to work on this I was under the impression that things would be simple in php because numbers and string normally change depending on whats being done to them and if you multiplied two variables they would try to cast them self as numbers. And javascript would be harder cause they don't. WRONG

    I made a simple xml file, called multi.xml:
    Code:
    <?xml version="1.0"?>
    <stuff>
      <area>
        <id>First</id>
        <base>100.25</base>
        <multiplyfactor>.5</multiplyfactor>
      </area>
      <area>
        <id>Second</id>
        <base>50</base>
        <multiplyfactor>0.5</multiplyfactor>
      </area>
    </stuff>
    Then worked on it in js and then in php. Here is the results and hope this will help you if you need to preform math on xml elements.
    First js:
    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <script>
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.open("GET","multi.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML;
    
    var x=xmlDoc.getElementsByTagName("area");
    
    for (i=0; i<=x.length; i++)
    {
    	var one = x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
    	var two = x[i].getElementsByTagName("base")[0].childNodes[0].nodeValue;
    	var three = x[i].getElementsByTagName("multiplyfactor")[0].childNodes[0].nodeValue;
    
    	document.write(one+"<br />");
    	document.write(two+"<br />");
    	document.write(three+"<br />");
    
    	var four = three * two;
    	document.write(two+" * "+three+" = "+four+"<br />---------<br />");
    }
    </script>
    </body>
    </html>
    Here's the same thing in php. NOTE: I had a problem with the math because php did not change the variable to a number when I tried to multiply them together.
    PHP Code:
    <?php
    $xml 
    simplexml_load_file("multi.xml");
    $area $xml->area;

    for(
    $i 0$i count($area); $i++)
    {
        
    $id $area[$i]->id;
        echo 
    $id "<br />";
        
    $base $area[$i]->base;
        echo 
    $base "<br />";
        
    $factor $area[$i]->multiplyfactor;
        echo 
    $factor "<br />";
        if(!
    is_numeric($base)) $base = (float)$base;
        if(!
    is_numeric($factor)) $factor = (float)$factor;
        
    $answer $base $factor;
        echo 
    $answer;
        echo 
    '<br />===================================<br />';
    }
    ?>
    The "How do you know which is a number" question. You have to know if your going to use it to preform math.

  2. #17
    New Coder
    Join Date
    Dec 2007
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    As has been said above, they are all text. If you can tell me how you can find the difference between them using the schema please let me know. I don't think the schema tells you if something is a time, a number, etc..



    The "How do you know which is a number" question. You have to know if your going to use it to preform math.
    schemas should have a data type attribute - that's how you could tell the software what to look for.
    <xs:element name="prizeamount" type="xs:decimal"/>
    <xs:element name="prizecode" type="xs:integer"/>

  3. #18
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,096
    Thanks
    23
    Thanked 594 Times in 593 Posts
    You know, for being the next BIG thing on the internet, there is so little information about it. I have found nothing about retrieving elements from the schema. Spent yesterday looking. From what I found out the schema is just used in writing the xml file and that's it. If you find out any thing let use know.


 
Page 2 of 2 FirstFirst 12

Posting Permissions

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