w
clone your own copy | download snapshot

Snapshots | iceberg

No images in this repository’s iceberg at this time

Inside this repository

partition.html
text/html

Download raw (2.3 KB)

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery.parseXML demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="partition.js"></script>
  <style>
  #input{
    height:200px;
    width:400px;
  }
  </style>
</head>
<body>
  <p class="desc">XML</p>
  <p class="desc"><textarea id="input">
    <axis title="Faire un gateau" tag="ordered">
      <axis title="Prendre une jatte plate"></axis>
      <axis title="Ajouter oeuf et farine"></axis>
    </axis>
  </textarea></p>
  <p><input type="button" id="parse" value="parse"></p>
  <p id="desc">éléments décodés</p>
  <p id="output"></p>

  <script>
  $('#parse').click(function(){
    listAxis();
  });

  function listAxis() {
    var xml = $('#input').val().replace(/\n/g, ""), xmlDoc = $.parseXML( xml ), xmld = $( xmlDoc );
    // variable to accumulate markup
    var markup = "";
    // worker function local to makeToc
    var ctag='';
    function processXml() {
      var ltag='';
      if(ctag.length>0){
        ltag=ctag;
      }
      var ptag='ordered';
      if($(this).parent().attr("tag")){
        ptag=$(this).parent().attr("tag");
      }
      markup += "<li>" + $(this).attr("title") + " "+ptag+" ";
      if($(this).attr("tag")){
        ctag=$(this).attr("tag");
      }else{
        ctag='';
      }
      if (this.nodeName == "axis") {
        if($(this).children().length>0){
          markup += "<ul>";
          // recurse on book children
          //$(this).find("axis").each(processXml);
          $(this).children().each(processXml);
          markup += "</ul>";
        }
      }
      markup += "</li>";

    }
    // call worker function on all children
    xmld.children().each(processXml);
    console.log(markup);
    $('#output').html(markup);
    //return markup;
  }
  //var tocOutput = makeToc($(toc));

  function parseXML(){
    var xml = $('#input').val().replace(/\n/g, ""), xmlDoc = $.parseXML( xml ), xmld = $( xmlDoc );
    //console.log($axis);
    //console.log($axis[0].attributes.getNamedItem('title'));
    console.log(xmld.children()[0].childNodes);
    for(var i=0;i<xmld.children()[0].childNodes.length;i++){
      console.log(xmld.children()[0].childNodes[i].attributes[0].textContent);
    }
    $('axis', xmld).each(function (i) {
      //Do something
      console.log($(this));
    });
  }

  </script>

</body>
</html>