xml中的注释

@param xmlElement
489428
@Override
    public void addComment(XmlElement xmlElement) {
        xmlElement.addElement(new TextElement("<!--"));
        StringBuilder sb = new StringBuilder();
        sb.append("  WARNING - ");
        sb.append(MergeConstants.NEW_ELEMENT_TAG);
        xmlElement.addElement(new TextElement(sb.toString()));
        xmlElement.addElement(new TextElement("-->"));
    }
673435
public void startElement(String namespaceURI, String localName,
                             String qName, Attributes atts) throws SAXException {
        trace("startElement:" + localName + "~" + qName);
        Element newElement = createElement(namespaceURI, qName, atts);
        appendNode(newElement);
        currentElement = newElement;
    }
1192411
public static XElement parseXMLFragment(XMLStreamReader in) throws XMLStreamException {
        if (in.hasNext()) {
            in.next();
            return parseXMLActiveFragment(in);
        }
        return null;
    }
686676
@Override
  protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException {

    // Find out if the our namespace already has been defined, and if so, get the prefix.
    //
    final String namespace = CurrentAddressType.TYPE_NAME.getNamespaceURI();
    Optional<String> _prefix = xmlObject.getNamespaceManager()
      .getNamespaces()
      .stream()
      .filter(n -> namespace.equals(n.getNamespaceURI()))
      .map(n -> n.getNamespacePrefix())
      .findFirst();
    String prefix = _prefix.isPresent() ? _prefix.get() : CurrentAddressType.TYPE_NAME.getPrefix();
    
    StringBuilder sb = new StringBuilder();

    final List<XMLObject> childXMLObjects = xmlObject.getOrderedChildren();
    if (childXMLObjects != null && childXMLObjects.size() > 0) {
      for (final XMLObject childXMLObject : childXMLObjects) {
        if (childXMLObject == null) {
          continue;
        }
        if (!(childXMLObject instanceof XSString)) {
          throw new MarshallingException("Unexpected type of child element - " + childXMLObject.getClass().getName());
        }
        XSString childString = (XSString) childXMLObject;
        if (childString.getValue() == null) {
          continue;
        }
        String localPart = childString.getElementQName().getLocalPart();
        sb.append(String.format("<%s:%s>%s</%s:%s>", prefix, localPart, childString.getValue(), prefix, localPart));
      }
    }
    if (sb.length() > 0) {
      byte[] bytes;
      try {
        bytes = sb.toString().getBytes("UTF-8");
      }
      catch (UnsupportedEncodingException e) {
        throw new MarshallingException(e);
      }
      String base64String = Base64Support.encode(bytes, true);
      ElementSupport.appendTextContent(domElement, base64String);
    }
  }
278448
protected void createParentXmlElements(CmsXmlContent xmlContent, String xmlPath, Locale l) {

        if (CmsXmlUtils.isDeepXpath(xmlPath)) {
            String parentPath = CmsXmlUtils.removeLastXpathElement(xmlPath);
            if (null == xmlContent.getValue(parentPath, l)) {
                createParentXmlElements(xmlContent, parentPath, l);
                xmlContent.addValue(m_cms, parentPath, l, CmsXmlUtils.getXpathIndexInt(parentPath) - 1);
            }
        }

    }
321491
@Nullable
  public ExpressionTreeElement addTreeElement(@Nonnull final ExpressionTreeElement element) {
    assertNotEmptySlot();
    assertNotNull("The element is null", element);

    final int newElementPriority = element.getPriority();

    ExpressionTreeElement result = this;

    final ExpressionTreeElement parentTreeElement = this.parentTreeElement;

    final int currentPriority = getPriority();

    if (newElementPriority < currentPriority) {
      if (parentTreeElement == null) {
        element.addTreeElement(this);
        result = element;
      } else {
        result = parentTreeElement.addTreeElement(element);
      }
    } else if (newElementPriority == currentPriority) {
      if (parentTreeElement != null) {
        parentTreeElement.replaceElement(this, element);
      }
      if (element.nextChildSlot >= element.childElements.length) {
        throw new PreprocessorException("[Expression]Can't process expression item, may be wrong number of arguments", this.sourceString, this.includeStack, null);
      }
      element.childElements[element.nextChildSlot] = this;
      element.nextChildSlot++;
      this.parentTreeElement = element;
      result = element;
    } else if (isFull()) {
      final int lastElementIndex = getArity() - 1;

      final ExpressionTreeElement lastElement = childElements[lastElementIndex];
      if (lastElement.getPriority() > newElementPriority) {
        element.addElementToNextFreeSlot(lastElement);
        childElements[lastElementIndex] = element;
        element.parentTreeElement = this;
        result = element;
      }

    } else {
      addElementToNextFreeSlot(element);
      result = element;
    }
    return result;
  }
133501
@Override
  public void startElement(String namespaceURI, String lName,
      String qName, Attributes attrs) throws SAXException {
    if (qName.equals(RULE)) {
      translations.clear();
      id = attrs.getValue("id");
      if (!(inRuleGroup && defaultOff)) {
        defaultOff = "off".equals(attrs.getValue("default"));
      }
      if (inRuleGroup && id == null) {
        id = ruleGroupId;
      }
      correctExamples = new ArrayList<>();
      incorrectExamples = new ArrayList<>();
    } else if (qName.equals(PATTERN)) {
      inPattern = true;
      String languageStr = attrs.getValue("lang");
      if (Languages.isLanguageSupported(languageStr)) {
        language = Languages.getLanguageForShortCode(languageStr);
      }
    } else if (qName.equals(TOKEN)) {
      setToken(attrs);
    } else if (qName.equals(TRANSLATION)) {
      inTranslation = true;
      String languageStr = attrs.getValue("lang");
      if (Languages.isLanguageSupported(languageStr)) {
        Language tmpLang = Languages.getLanguageForShortCode(languageStr);
        currentTranslationLanguage = tmpLang;
        if (tmpLang.equalsConsiderVariantsIfSpecified(motherTongue)) {
          translationLanguage = tmpLang;
        }
      }
    } else if (qName.equals(EXAMPLE)) {
      correctExample = new StringBuilder();
      incorrectExample = new StringBuilder();
      if (attrs.getValue(TYPE).equals("incorrect")) {
        inIncorrectExample = true;
      } else if (attrs.getValue(TYPE).equals("correct")) {
        inCorrectExample = true;
      } else if (attrs.getValue(TYPE).equals("triggers_error")) {
        throw new RuntimeException("'triggers_error' is not supported for false friend XML");
      }
    } else if (qName.equals(MESSAGE)) {
      inMessage = true;
      message = new StringBuilder();
    } else if (qName.equals(RULEGROUP)) {
      ruleGroupId = attrs.getValue("id");
      inRuleGroup = true;
      defaultOff = "off".equals(attrs.getValue(DEFAULT));
    }
  }
537840
private void sameElementNode() throws XMLStreamException, TTException {
        // Update variables.
        mInsert = EInsert.NOINSERT;
        mDelete = EDelete.NODELETE;
        mInserted = false;
        mInsertedEndTag = false;
        mRemovedNode = false;

        // Check if last node reached.
        // checkIfLastNode(false);

        // Skip whitespace events.
        skipWhitespaces(mReader);

        // Move transaction.
        final ElementNode element = (ElementNode)mWtx.getNode();

        if (element.hasFirstChild()) {
            /*
             * If next event needs to be inserted, it has to be inserted at the
             * top of the subtree, as first child.
             */
            mInsert = EInsert.ATTOP;
            mWtx.moveTo(((ITreeStructData)mWtx.getNode()).getFirstChildKey());

            if (mReader.peek().getEventType() == XMLStreamConstants.END_ELEMENT) {
                /*
                 * Next event is an end tag, so the current child element, where
                 * the transaction currently is located needs to be removed.
                 */
                mKeyMatches = -1;
                mDelete = EDelete.ATBOTTOM;
                deleteNode();
            }
            // } else if (mReader.peek().getEventType() ==
            // XMLStreamConstants.END_ELEMENT
            // &&
            // !mReader.peek().asEndElement().getName().equals(mWtx.getQNameOfCurrentNode()))
            // {
            // /*
            // * Node must be removed when next end tag doesn't match the
            // current name and it has no children.
            // */
            // mKeyMatches = -1;
            // mDelete = EDelete.ATBOTTOM;
            // deleteNode();
        } else if (mReader.peek().getEventType() != XMLStreamConstants.END_ELEMENT) {
            /*
             * Treetank transaction can't find a child node, but StAX parser
             * finds one, so it must be inserted as a first child of the current
             * node.
             */
            mInsert = EInsert.ATTOP;
            mEmptyElement = true;
        } else {
            mInsert = EInsert.ATMIDDLEBOTTOM;
        }
    }
841969
@SuppressWarnings("unchecked")
    private void setValue(List<Element> elements, String attrName, Object pojo,
                          CustomPropertyDescriptor field) {
        XmlNode attrXmlNode = field.getAnnotation(XmlNode.class);
        log.debug("要赋值的fieldName为{}", field.getName());
        final XmlTypeConvert convert = XmlTypeConverterUtil.resolve(attrXmlNode, field);

        Class<? extends Collection> collectionClass;
        Class<? extends Collection> real = (Class<? extends Collection>) field.getRealType();

        if (attrXmlNode != null) {
            collectionClass = attrXmlNode.arrayType();
            if (!collectionClass.equals(real) && !real.isAssignableFrom(collectionClass)) {
                log.warn("用户指定的集合类型[{}]不是字段的实际集合类型[{}]的子类，使用字段的实际集合类型", collectionClass, real);
                collectionClass = real;
            }
        } else {
            collectionClass = real;
        }

        if (!StringUtils.isEmpty(attrXmlNode.arrayRoot()) && !elements.isEmpty()) {
            elements = elements.get(0).elements(attrXmlNode.arrayRoot());
        }

        //将数据转换为用户指定数据
        List<?> list = elements.stream().map(d -> convert.read(d, attrName))
            .collect(Collectors.toList());

        if (!trySetValue(list, pojo, field, collectionClass)) {
            //使用注解标记的类型赋值失败并且注解的集合类型与实际字段类型不符时尝试使用字段实际类型赋值
            if (!trySetValue(list, pojo, field, real)) {
                log.warn("无法为字段[{}]赋值", field.getName());
            }
        }
    }
270828
protected XmlElement transformElement(org.dom4j.Element node) {
    XmlElement xe = new XmlElement(node.getName());

    // 设置元素的属性 
    @SuppressWarnings("unchecked")
    Iterator<org.dom4j.Attribute> iterator = node.attributeIterator();
    while (iterator.hasNext()) {
      org.dom4j.Attribute ab = iterator.next();
      xe.addAttribute(new Attribute(ab.getName(), ab.getValue()));
    }
    // 深度优先遍历子节点
    @SuppressWarnings("unchecked")
    Iterator<org.dom4j.Node> niter = node.nodeIterator();
    while (niter.hasNext()) {
      org.dom4j.Node n = niter.next();
      // 文本节点
      if (n.getNodeType() == org.dom4j.Node.TEXT_NODE) {
        Text text = (Text) n;
        TextElement te = new TextElement(text.getText().trim());
        xe.addElement(te);
      }
      // 元素节点
      if (n.getNodeType() == org.dom4j.Node.ELEMENT_NODE) {
        xe.addElement(transformElement((org.dom4j.Element) n));
      }
      // 注释节点
      if (n.getNodeType() == org.dom4j.Node.COMMENT_NODE) {
        TextElement te = new TextElement(n.asXML().trim());
        xe.addElement(te);
      }
      // CDATA 节点
      if (n.getNodeType() == org.dom4j.Node.CDATA_SECTION_NODE) {
        TextElement te = new TextElement(n.asXML().trim());
        xe.addElement(te);
      }
    }
    return xe;
  }
483409
private XmlElement getXMLParam(Object o) throws XMLRPCException {
		XmlElement param = new XmlElement(XMLRPCClient.PARAM);
		XmlElement value = new XmlElement(XMLRPCClient.VALUE);
		param.addChildren(value);
		value.addChildren(serializerHandler.serialize(o));
		return param;
	}
397846
private void setValue(Element element, String attrName, Object pojo,
                          CustomPropertyDescriptor field) {
        XmlNode attrXmlNode = field.getAnnotation(XmlNode.class);
        log.debug("要赋值的fieldName为{}", field.getName());
        final XmlTypeConvert convert = XmlTypeConverterUtil.resolve(attrXmlNode, field);
        if (!BeanUtils.setProperty(pojo, field.getName(), convert.read(element, attrName))) {
            log.debug("copy中复制{}时发生错误，属性[{}]的值将被忽略", field.getName(), field.getName());
        }
    }
634918
public void parseString(String xml) throws ParserException {

        try {
            nanoElement.parseString(xml);
        } catch (XMLParseException e) {
            throw new ParserException(e.getMessage());
        }
    }
1306026
function(xmlElement) {
    // Note: Until January 2013 this block did not have mutations,
    // so 'statement' defaults to false and 'at' defaults to true.
    var isStatement = (xmlElement.getAttribute('statement') == 'true');
    this.updateStatement_(isStatement);
    var isAt = (xmlElement.getAttribute('at') != 'false');
    this.updateAt_(isAt);
  }
1005022
public XMLWriter startElement(String element) {
        append("<" + element);
        if (rootElement && xmlns != null) {
            append(" xmlns=\"" + xmlns + "\"");
            rootElement = false;
        }
        append(">");
        elementStack.push(element);
        return this;
    }
583001
@Override
    public Element getXML(Document root) {
        Element node = root.createElement("folder");
        this.addNodeAttributes(node);
        return node;
    }
1189513
static Optional<XmlElement> getErrorElement(XmlElement rootXmlElement) {
    Optional<XmlElement> elem = rootXmlElement.getChildOpt("error");
    if (elem.isPresent()) {
      ApiException error = elem.transform(toApiException()).get();
      log.error(error.getCode() + ": " + error.getValue());
    }
    return elem;
  }