⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlp.js

📁 这个weblogging 设计得比较精巧
💻 JS
📖 第 1 页 / 共 3 页
字号:

/// CDATASection ///////////////////////////////////////////////////////////////

CDATASection.prototype = new Text();
CDATASection.prototype.constructor = CDATASection;
  // CDATASection : Text

function CDATASection( ownerDoc, data ) {
  
  // inherited from Text : CharacterData
  this.data = data;
  
  // inherited from Text : CharacterData : Node
  this.nodeName = "#cdata-section";
  this.nodeType = Node.CDATA_SECTION_NODE;
  this.nodeValue = data;
  this.ownerDocument = ownerDoc;
}

/// EntityReference ////////////////////////////////////////////////////////////

EntityReference.prototype = new Node();
EntityReference.prototype.constructor = EntityReference;
  // EntityReference : Node

function EntityReference( ownerDoc, name ) {
  
  // inherited from Node
  this.nodeName = name;
  this.nodeType = Node.ENTITY_REFERENCE_NODE;
  this.ownerDocument = ownerDoc;
}

/// ProcessingInstruction //////////////////////////////////////////////////////

ProcessingInstruction.prototype = new Node();
ProcessingInstruction.prototype.constructor = ProcessingInstruction;
  // ProcessingInstruction : Node

function ProcessingInstruction( ownerDoc, target, data ) {
  this.target = target;
  this.data = data;
  
  // inherited from Node
  this.nodeName = target;
  this.nodeType = Node.PROCESSING_INSTRUCTION_NODE;
  this.nodeValue = data;
  this.ownerDocument = ownerDoc;
}

ProcessingInstruction.prototype.getData =
function() {
  return this.data;
}

ProcessingInstruction.prototype.getTarget =
function() {
  return this.target;
}

ProcessingInstruction.prototype.setData =
function( data ) {
  this.setNodeValue( data );
}

ProcessingInstruction.prototype.setNodeValue =
function( value ) {
  this.data = data;
  this.nodeValue = data;
}

/// Comment ////////////////////////////////////////////////////////////////////

Comment.prototype = new CharacterData();
Comment.prototype.constructor = Comment;
  // Comment : CharacterData

function Comment( ownerDoc, data ) {
  // inherited from CharacterData
  this.data = data;
  
  // inherited from CharacterData : Node
  this.nodeName = "#comment";
  this.nodeType = Node.COMMENT_NODE;
  this.nodeValue = data;
  this.ownerDocument = ownerDoc;
}

/// Document ///////////////////////////////////////////////////////////////////

Document.prototype = new Node();
Document.prototype.constructor = Document;
  // Document : Node

function Document() {
  this.doctype = null;
  this.implementation = null;
  this.documentElement = null;

  // inherited from Node
  this.childNodes = new NodeList();
  this.nodeName = "#document";
  this.nodeType = Node.DOCUMENT_NODE;
  this.ownerDocument = this;
}

Document.prototype.createAttribute =
function( name, value ) {
  return new Attr( this, name, value );
}

Document.prototype.createCDATASection =
function( data ) {
  return new CDATASection( this, data );
}

Document.prototype.createComment =
function( data ) {
  return new Comment( this, data );
}

Document.prototype.createDocumentFragment =
function() {
  return new DocumentFragment( this );
}

Document.prototype.createElement =
function( tagName ) {
  return new Element( this, tagName );
}

Document.prototype.createEntityReference =
function( name ) {
  return new EntityReference( this, name );
}

Document.prototype.createProcessingInstruction =
function( target, data ) {
  return new ProcessingInstruction( this, target, data );
}

Document.prototype.createTextNode =
function( data ) {
  return new Text( this, data );
}

Document.prototype.getDoctype =
function() {
  return this.doctype;
}

Document.prototype.getDocumentElement =
function() {
  return this.documentElement;
}

Document.prototype.getElementsByTagName =
function( tagName ) {
  return new DeepNodeList( this, tagName );
}

Document.prototype.getImplementation =
function() {
  // :REVISIT:
  return this.implementation;
}

/// DocumentType ///////////////////////////////////////////////////////////////

DocumentType.prototype = new Node();
DocumentType.prototype.constructor = DocumentType;
  // DocumentType : Node

function DocumentType( ownderDoc, name ) {
  this.name = name;
  this.entities = null;
  this.notations = null;
  
  // inherited from Node
  this.nodeName = name;
  this.nodeType = Node.DOCUMENT_TYPE_NODE;
  this.ownerDocument = ownderDoc;
}

DocumentType.prototype.getEntities = 
function() {
  // :REVISIT: change to DOMException
  throw new ParseError( "Not implemented" );
}

DocumentType.prototype.getName = 
function() {
  return this.name;
}

DocumentType.prototype.getNotations = 
function() {
  // :REVISIT: change to DOMException
  throw new ParseError( "Not implemented" );
}

/// DocumentFragment ///////////////////////////////////////////////////////////

DocumentFragment.prototype = new Node();
DocumentFragment.prototype.constructor = DocumentFragment;
  // DocumentFragment : Node

function DocumentFragment( ownerDoc ) {
  
  // inherited from Node
  this.childNodes = new NodeList();
  this.nodeName = "#document-fragment";
  this.nodeType = Node.DOCUMENT_FRAGMENT_NODE;
  this.ownerDocument = ownerDoc;
}

/// NodeList ///////////////////////////////////////////////////////////////////

function NodeList() {
  this.length = 0;
}

NodeList.prototype.getLength =
function() {
  return this.length;
}

NodeList.prototype.item =
function( index ) {
  var item;
  item = ( index < 0 ) ? this[ this.length + index ]
                       : this[ index ];
  return ( item || null );
}

NodeList.prototype.add =
function( node ) {
  this[ this.length++ ] = node;
}

/// DeepNodeList ///////////////////////////////////////////////////////////////

DeepNodeList.prototype = new NodeList();
DeepNodeList.prototype.constructor = DeepNodeList;
  // DeepNodeList : NodeList

function DeepNodeList( rootNode, tagName ) {
  this.rootNode = rootNode;
  this.tagName = tagName;
  this.getElementsByTagName( rootNode );
}

DeepNodeList.prototype.getElementsByTagName =
function( contextNode ) {
  var nextNode;
  while ( contextNode != null ) {
    if ( contextNode.hasChildNodes() ) {
      contextNode = contextNode.firstChild;
    }
    else if ( contextNode != this.rootNode &&
              null != ( next = contextNode.nextSibling ) ) {
      contextNode = next;
    }
    else {
      next = null;
      for ( ; contextNode != this.rootNode;
           contextNode = contextNode.parentNode ) {
        next = contextNode.nextSibling;
        if ( next != null ) {
          break;
        }
      }
      contextNode = next;
    }
    if ( contextNode != this.rootNode &&
         contextNode != null &&
         contextNode.nodeType == Node.ELEMENT_NODE ) {
      if ( this.tagName == "*" || contextNode.tagName == this.tagName ) {
        this.add( contextNode );
      }
    }
  }
  return null;
}

/// NamedNodeMap ///////////////////////////////////////////////////////////////

function NamedNodeMap() {
  this.length = 0;
}

NamedNodeMap.prototype.getLength =
function() {
  return this.length;
}

NamedNodeMap.prototype.getNamedItem =
function( name ) {
  return ( this[ name ] || null );
}

NamedNodeMap.prototype.item =
function( index ) {
  var item;
  item = ( index < 0 ) ? this[ this.length + index ]
                       : this[ index ];
  return ( item || null );
}

NamedNodeMap.prototype.removeNamedItem =
function( name ) {
  var removed = this[ name ];

  if ( !removed ) {
    return null;
  }

  delete this[ name ];
  for ( var i = 0; i < this.length - 1; i++ ) {
    if ( !this[i] ) {
      this[i] = this[ i + 1 ];
      delete this[ i + 1 ];
    }
  }
  this.length--;
  return removed;
}

NamedNodeMap.prototype.setNamedItem =
function( node ) {
  var nodeName = node.getNodeName();
  var item = this.getNamedItem( nodeName );
  this[ nodeName ] = node;
  
  if ( item == null ) {
    this[ this.length++ ] = node;
  }
  
  return item;
}

/// ParseError /////////////////////////////////////////////////////////////////

ParseError.prototype = new Error();
ParseError.prototype.constructor = ParseError;
  // ParseError : Error

function ParseError( message ) {
  this.message = message;
}

/// DOMException ///////////////////////////////////////////////////////////////

// :REVISIT:
// not currently used

DOMException.prototype = new Error();
DOMException.prototype.constructor = DOMException;
  // DOMException : Error

DOMException.INDEX_SIZE_ERR              = 1;
DOMException.DOMSTRING_SIZE_ERR          = 2;
DOMException.HIERARCHY_REQUEST_ERR       = 3;
DOMException.WRONG_DOCUMENT_ERR          = 4;
DOMException.INVALID_CHARACTER_ERR       = 5;
DOMException.NO_DATA_ALLOWED_ERR         = 6;
DOMException.NO_MODIFICATION_ALLOWED_ERR = 7;
DOMException.NOT_FOUND_ERR               = 8;
DOMException.NOT_SUPPORTED_ERR           = 9;
DOMException.INUSE_ATTRIBUTE_ERR         = 10;

function DOMException( code, message ) {
  this.code = code;
  this.message = message;
}

/// XMLParser //////////////////////////////////////////////////////////////////

XMLParser.VERSION = 1.0;

function XMLParser() {
  this.doc = new Document();
  this.xml = null;

  this.openedTags = new Array();
  this.contextNodes = new Array( this.doc );
}

XMLParser.prototype.parse =
function( xml ) {
  this.xml = xml.trim();
  this.processProlog();
  this.processRootElement();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -