org.dom4j.Element.addNamespace()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(476)

本文整理了Java中org.dom4j.Element.addNamespace()方法的一些代码示例,展示了Element.addNamespace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.addNamespace()方法的具体详情如下:
包路径:org.dom4j.Element
类名称:Element
方法名:addNamespace

Element.addNamespace介绍

[英]Adds a namespace to this element for use by its child content
[中]将命名空间添加到此元素以供其子内容使用

代码示例

代码示例来源:origin: igniterealtime/Openfire

private String createSessionRestartResponse()
{
  final Element response = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) );
  response.addNamespace("stream", "http://etherx.jabber.org/streams");
  final Element features = response.addElement("stream:features");
  for (Element feature : getAvailableStreamFeaturesElements()) {
    features.add(feature);
  }
  return response.asXML();
}

代码示例来源:origin: igniterealtime/Openfire

private static String createSessionCreationResponse(HttpSession session) throws DocumentException {
  Element response = DocumentHelper.createElement( QName.get( "body", "http://jabber.org/protocol/httpbind" ) );
  response.addNamespace("stream", "http://etherx.jabber.org/streams");
  response.addAttribute("from", session.getServerName());
  response.addAttribute("authid", session.getStreamID().getID());
  response.addAttribute("sid", session.getStreamID().getID());
  response.addAttribute("secure", Boolean.TRUE.toString());
  response.addAttribute("requests", String.valueOf(session.getMaxRequests()));
  response.addAttribute("inactivity", String.valueOf(session.getInactivityTimeout()));
  response.addAttribute("polling", String.valueOf(session.getMaxPollingInterval()));
  response.addAttribute("wait", String.valueOf(session.getWait()));
  if ((session.getMajorVersion() == 1 && session.getMinorVersion() >= 6) ||
    session.getMajorVersion() > 1) {
    response.addAttribute("hold", String.valueOf(session.getHold()));
    response.addAttribute("ack", String.valueOf(session.getLastAcknowledged()));
    response.addAttribute("maxpause", String.valueOf(session.getMaxPause()));
    response.addAttribute("ver", String.valueOf(session.getMajorVersion())
        + "." + String.valueOf(session.getMinorVersion()));
  }
  Element features = response.addElement("stream:features");
  for (Element feature : session.getAvailableStreamFeaturesElements()) {
    features.add(feature);
  }
  return response.asXML();
}

代码示例来源:origin: igniterealtime/Openfire

final String namespaceUri = pp.getNamespaceUri( i );
if ( namespacePrefix != null ) {
  newElement.addNamespace(namespacePrefix, namespaceUri);
} else if ( parent == null && IGNORED_NAMESPACE_ON_STANZA.contains( namespaceUri ) ) {
  newElement.addNamespace( "", namespaceUri );

代码示例来源:origin: org.dom4j/dom4j

public void addAttribute(String namespaceURI, String localName,
    String rawName, String value, boolean isNamespaceDeclaration)
    throws XmlPullParserException {
  if (isNamespaceDeclaration) {
    String prefix = "";
    int idx = rawName.indexOf(':');
    if (idx > 0) {
      prefix = rawName.substring(0, idx);
    }
    element.addNamespace(prefix, namespaceURI);
  } else {
    QName qname = QName.get(rawName, namespaceURI);
    element.addAttribute(qname, value);
  }
}

代码示例来源:origin: webx/citrus

public void transform(Document document, String systemId) {
    Element root = document.getRootElement();
    root.addNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
    // <xsd:schema>
    if (W3C_XML_SCHEMA_NS_URI.equals(root.getNamespaceURI()) && "schema".equals(root.getName())) {
      Namespace xsd = DocumentHelper.createNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
      QName includeName = DocumentHelper.createQName("include", xsd);
      // for each <xsd:include>
      for (Iterator<?> i = root.elementIterator(includeName); i.hasNext(); ) {
        i.next();
        i.remove();
      }
      // 添加includes
      @SuppressWarnings("unchecked")
      List<Node> nodes = root.elements();
      int i = 0;
      for (Schema includedSchema : includes.values()) {
        Element includeElement = DocumentHelper.createElement(includeName);
        nodes.add(i++, includeElement);
        includeElement.addAttribute("schemaLocation", includedSchema.getName());
      }
    }
  }
};

代码示例来源:origin: webx/citrus

public void transform(Document document, String systemId) {
    Element root = document.getRootElement();
    root.addNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
    // <xsd:schema>
    if (W3C_XML_SCHEMA_NS_URI.equals(root.getNamespaceURI()) && "schema".equals(root.getName())) {
      Namespace xsd = DocumentHelper.createNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
      QName includeName = DocumentHelper.createQName("include", xsd);
      // for each <xsd:include>
      for (Iterator<?> i = root.elementIterator(includeName); i.hasNext(); ) {
        i.next();
        i.remove();
      }
      // 添加includes
      @SuppressWarnings("unchecked")
      List<Node> nodes = root.elements();
      int i = 0;
      for (Schema includedSchema : includes.values()) {
        Element includeElement = DocumentHelper.createElement(includeName);
        nodes.add(i++, includeElement);
        includeElement.addAttribute("schemaLocation", includedSchema.getName());
      }
    }
  }
};

代码示例来源:origin: webx/citrus

@Override
protected void visitRootElement() {
  // 为contribution schema添加默认namespace和targetNamespace的声明。
  // 由于contribution schema是被include到configuration point schema中的,所以这些声明不是必须的。
  // 但是Intellij IDEA似乎不能正确学习到contribution schema的namespace,除非加上这些声明。
  root.addNamespace("", thisCp.getNamespaceUri());
  root.addAttribute("targetNamespace", thisCp.getNamespaceUri());
}

代码示例来源:origin: webx/citrus

@Override
protected void visitRootElement() {
  // 为contribution schema添加默认namespace和targetNamespace的声明。
  // 由于contribution schema是被include到configuration point schema中的,所以这些声明不是必须的。
  // 但是Intellij IDEA似乎不能正确学习到contribution schema的namespace,除非加上这些声明。
  root.addNamespace("", thisCp.getNamespaceUri());
  root.addAttribute("targetNamespace", thisCp.getNamespaceUri());
}

代码示例来源:origin: webx/citrus

@Override
protected void visitRootElement() {
  // 为contribution schema添加默认namespace和targetNamespace的声明。
  // 由于contribution schema是被include到configuration point schema中的,所以这些声明不是必须的。
  // 但是Intellij IDEA似乎不能正确学习到contribution schema的namespace,除非加上这些声明。
  root.addNamespace("", thisCp.getNamespaceUri());
  root.addAttribute("targetNamespace", thisCp.getNamespaceUri());
}

代码示例来源:origin: webx/citrus

public void transform(Document document, String systemId) {
    Element root = document.getRootElement();
    root.addNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
    // <xsd:schema>
    if (W3C_XML_SCHEMA_NS_URI.equals(root.getNamespaceURI()) && "schema".equals(root.getName())) {
      Namespace xsd = DocumentHelper.createNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
      QName includeName = DocumentHelper.createQName("include", xsd);
      // for each <xsd:include>
      for (Iterator<?> i = root.elementIterator(includeName); i.hasNext(); ) {
        i.next();
        i.remove();
      }
      // 添加includes
      @SuppressWarnings("unchecked")
      List<Node> nodes = root.elements();
      int i = 0;
      for (Schema includedSchema : includes.values()) {
        Element includeElement = DocumentHelper.createElement(includeName);
        nodes.add(i++, includeElement);
        includeElement.addAttribute("schemaLocation", includedSchema.getName());
      }
    }
  }
};

代码示例来源:origin: org.dom4j/dom4j

/**
 * Constructs a new DOM4J Element from the provided StartElement event. All
 * attributes and namespaces will be added to the returned element.
 * 
 * @param startEvent
 *            The StartElement event from which to construct the new DOM4J
 *            Element.
 * 
 * @return The Element constructed from the provided StartElement event.
 */
public Element createElement(StartElement startEvent) {
  QName qname = startEvent.getName();
  org.dom4j.QName elemName = createQName(qname);
  Element elem = factory.createElement(elemName);
  // create attributes
  for (Iterator<Attribute> i = startEvent.getAttributes(); i.hasNext();) {
    Attribute attr = i.next();
    elem.addAttribute(createQName(attr.getName()), attr.getValue());
  }
  // create namespaces
  for (Iterator<Namespace> i = startEvent.getNamespaces(); i.hasNext();) {
    Namespace ns = i.next();
    elem.addNamespace(ns.getPrefix(), ns.getNamespaceURI());
  }
  return elem;
}

代码示例来源:origin: webx/citrus

schemaRoot.addNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
schemaRoot.addNamespace("beans", BEANS_NAMESPACE_URI);
schemaRoot.addNamespace("springext", SPRINGEXT_BASE_URI);
schemaRoot.addNamespace("", configurationPoint.getNamespaceUri());

代码示例来源:origin: webx/citrus

schemaRoot.addNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
schemaRoot.addNamespace("beans", BEANS_NAMESPACE_URI);
schemaRoot.addNamespace("springext", SPRINGEXT_BASE_URI);
schemaRoot.addNamespace("", configurationPoint.getNamespaceUri());

代码示例来源:origin: webx/citrus

schemaRoot.addNamespace("xsd", W3C_XML_SCHEMA_NS_URI);
schemaRoot.addNamespace("beans", BEANS_NAMESPACE_URI);
schemaRoot.addNamespace("springext", SPRINGEXT_BASE_URI);
schemaRoot.addNamespace("", configurationPoint.getNamespaceUri());

代码示例来源:origin: pentaho/pentaho-kettle

data.rssElement.addNamespace(
 environmentSubstitute( meta.getNameSpacesTitle()[i] ),
 environmentSubstitute( meta.getNameSpaces()[i] ) );

代码示例来源:origin: webx/citrus

root.addNamespace(nsPrefix, ns);

代码示例来源:origin: webx/citrus

root.addNamespace(nsPrefix, ns);

代码示例来源:origin: webx/citrus

root.addNamespace(nsPrefix, ns);

代码示例来源:origin: org.dom4j/dom4j

newElement.addNamespace(pp.getNamespacePrefix(i),
    pp.getNamespaceUri(i));

代码示例来源:origin: dom4j/dom4j

public void testBug1148333() {
  DOMDocumentFactory factory = (DOMDocumentFactory) DOMDocumentFactory
      .getInstance();
  DOMDocument doc = (DOMDocument) factory.createDocument();
  Element el = doc.addElement("root");
  el.addNamespace("pref2", "uri2");
  DOMDocument clone = (DOMDocument) doc.cloneNode(true);
  
  assertNotSame(doc, clone);
  assertNodesEqual(doc, clone);
}

相关文章

Element类方法