コード例 #1
0
ファイル: XmlElement.java プロジェクト: jimmystest/nokogiri
 @Override
 public void accept(ThreadContext context, SaveContextVisitor visitor) {
   visitor.enter((Element) node);
   XmlNodeSet xmlNodeSet = (XmlNodeSet) children(context);
   if (xmlNodeSet.length() > 0) {
     RubyArray array = (RubyArray) xmlNodeSet.to_a(context);
     for (int i = 0; i < array.getLength(); i++) {
       Object item = array.get(i);
       if (item instanceof XmlNode) {
         XmlNode cur = (XmlNode) item;
         cur.accept(context, visitor);
       } else if (item instanceof XmlNamespace) {
         XmlNamespace cur = (XmlNamespace) item;
         cur.accept(context, visitor);
       }
     }
   }
   visitor.leave((Element) node);
 }
コード例 #2
0
 public boolean enter(Element element) {
   String current = indentation.peek();
   buffer.append(current);
   if (needIndent()) {
     indentation.push(current + indentString);
   }
   String name = element.getTagName();
   buffer.append("<" + name);
   NamedNodeMap attrs = element.getAttributes();
   for (int i = 0; i < attrs.getLength(); i++) {
     Attr attr = (Attr) attrs.item(i);
     if (attr.getSpecified()) {
       buffer.append(" ");
       enter(attr);
       leave(attr);
     }
   }
   if (element.hasChildNodes()) {
     buffer.append(">");
     if (needBreakInOpening(element)) buffer.append("\n");
     return true;
   }
   // no child
   if (asHtml) {
     buffer.append(">");
   } else if (asXhtml) {
     buffer.append(" />");
   } else if (asXml && noEmpty) {
     buffer.append(">");
   } else {
     buffer.append("/>");
   }
   if (needBreakInOpening(element)) {
     buffer.append("\n");
   }
   return true;
 }
コード例 #3
0
 public void leave(Node node) {
   if (node instanceof Document) {
     leave((Document) node);
     return;
   }
   if (node instanceof Element) {
     leave((Element) node);
     return;
   }
   if (node instanceof Attr) {
     leave((Attr) node);
     return;
   }
   if (node instanceof Text) {
     leave((Text) node);
     return;
   }
   if (node instanceof CDATASection) {
     leave((CDATASection) node);
     return;
   }
   if (node instanceof Comment) {
     leave((Comment) node);
     return;
   }
   if (node instanceof DocumentType) {
     leave((DocumentType) node);
     return;
   }
   if (node instanceof Entity) {
     leave((Entity) node);
     return;
   }
   if (node instanceof EntityReference) {
     leave((EntityReference) node);
     return;
   }
   if (node instanceof Notation) {
     leave((Notation) node);
     return;
   }
   if (node instanceof ProcessingInstruction) {
     leave((ProcessingInstruction) node);
     return;
   }
 }