处理xml

 //解析xml返回html 深入两层
function AnalysisDeepXML(xml) {
    var html = '<ul id="browser" class="filetree">';
    $.get(xml, function (d) {
        $(d).find('node').each(function () {
            var $parentNode = $(this);
            var parentName = $parentNode.find('name').first().text();
            parentName = parentName.substring(0, parentName.lastIndexOf('('));
            var parentId = $parentNode.find('id').first().text();
            alert(parentName + "," + parentId);
            //                    var title = $node.attr("title");
            //                    var imageurl = $node.attr('imageurl');
            html += '<li><span title="' + parentId + '" class="folder">' + parentName + '</span>';
            var $children = $parentNode.find('children');
            if ($children != undefined) {
                html += '<ul>';
                $children.find('node').each(function () {
                    var $childrenNode = $(this);
                    var childrenName = $childrenNode.find('name').first().text();
                    var childrenNum = childrenName.substring(childrenName.lastIndexOf('(') + 1, childrenName.lastIndexOf(')'));
                    childrenName = childrenName.substring(0, childrenName.lastIndexOf('('));
                    var childrenId = $childrenNode.find('id').first().text();
                    html += '<li><span class="file" title="' + childrenId + '">' + childrenName + '</span></li>';
                });
                html += '</ul>';
            }
            html += '</li>';
        });
    });
    html += '</ul>';
    return html;
}

 

<?xml version="1.0" encoding="utf-8"?>
<tree parentId="0">
  <node>
    <id>T</id>
    <name>工业技术</name>
    <leaf>false</leaf>
    <hide>false</hide>
    <children>
      <node>
        <id>TA</id>
        <name>大学学报(工业技术)</name>
        <leaf>true</leaf>
        <hide>false</hide>
      </node>
      <node>
        <id>TB</id>
        <name>一般工业技术</name>
        <leaf>true</leaf>
        <hide>false</hide>
      </node>
    </children>
  </node>
</tree>

你可能感兴趣的:(html,xml,function,Class,browser,encoding)