org.jdom2.Element.addNamespaceDeclaration()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(116)

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

Element.addNamespaceDeclaration介绍

[英]Adds a namespace declarations to this element. This should not be used to add the declaration for this element itself; that should be assigned in the construction of the element. Instead, this is for adding namespace declarations on the element not relating directly to itself. It's used during output to for stylistic reasons move namespace declarations higher in the tree than they would have to be.
[中]

代码示例

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

public void registerNamespacesInto(Element element) {
  for (PluginNamespace namespace : xsdsFor.values()) {
    element.addNamespaceDeclaration(Namespace.getNamespace(namespace.prefix, namespace.uri));
  }
}

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

private Document createEmptyCruiseConfigDocument() {
  Element root = new Element("cruise");
  Namespace xsiNamespace = Namespace.getNamespace("xsi", XML_NS);
  root.addNamespaceDeclaration(xsiNamespace);
  registry.registerNamespacesInto(root);
  root.setAttribute("noNamespaceSchemaLocation", "cruise-config.xsd", xsiNamespace);
  String xsds = registry.xsds();
  if (!xsds.isEmpty()) {
    root.setAttribute("schemaLocation", xsds, xsiNamespace);
  }
  root.setAttribute("schemaVersion", Integer.toString(GoConstants.CONFIG_SCHEMA_VERSION));
  return new Document(root);
}

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

@Test
public void registerAllConfigTagImplementationsProvidedByPlugins() throws MalformedURLException {
  BundleContext execCtx = PluginTestUtil.bundleCtxWithHeaders(DataStructureUtils.m(PluginNamespace.XSD_NAMESPACE_PREFIX, "exec", PluginNamespace.XSD_NAMESPACE_URI, "uri-exec"));
  PluggableViewModelFactory<PluginExec> factory = mock(PluggableViewModelFactory.class);
  ConfigTypeExtension exec = new TestTaskConfigTypeExtension<>(PluginExec.class, factory);
  ConfigurationExtension execTag = new ConfigurationExtension<>(
      new PluginNamespace(execCtx, new URL("file:///exec")), exec);
  BundleContext antCtx = PluginTestUtil.bundleCtxWithHeaders(DataStructureUtils.m(PluginNamespace.XSD_NAMESPACE_PREFIX, "ant", PluginNamespace.XSD_NAMESPACE_URI, "uri-ant"));
  ConfigTypeExtension ant = new TestTaskConfigTypeExtension<>(PluginAnt.class, mock(PluggableViewModelFactory.class));
  ConfigurationExtension antTag = new ConfigurationExtension<>(
      new PluginNamespace(antCtx, new URL("file:///ant")), ant);
  when(pluginExtns.configTagImplementations()).thenReturn(Arrays.asList(execTag, antTag));
  ConfigElementImplementationRegistry registry = new ConfigElementImplementationRegistry(pluginExtns);
  assertThat(registry.xsds(), containsString("uri-exec file:/exec"));
  assertThat(registry.xsds(), containsString("uri-ant file:/ant"));
  List<Class<? extends Task>> implementationTypes = registry.implementersOf(Task.class);
  assertThat(implementationTypes.contains(PluginExec.class), is(true));
  assertThat(implementationTypes.contains(PluginAnt.class), is(true));
  Element mock = mock(Element.class);
  registry.registerNamespacesInto(mock);
  verify(mock).addNamespaceDeclaration(Namespace.getNamespace("exec", "uri-exec"));
  verify(mock).addNamespaceDeclaration(Namespace.getNamespace("ant", "uri-ant"));
}

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

@Override
public void addNamespaceDeclaration(Element parent, Namespace additional) {
  parent.addNamespaceDeclaration(additional);
}

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

/**
 * This will take the supplied <code>{@link Element}</code> and transfer its
 * namespaces to the global namespace storage.
 * 
 * @param element
 *        <code>Element</code> to read namespaces from.
 */
private void transferNamespaces(final Element element) {
  for (final Namespace ns : declaredNamespaces) {
    if (ns != element.getNamespace()) {
      element.addNamespaceDeclaration(ns);
    }
  }
  declaredNamespaces.clear();
}

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

/**
 * Read an Element off the ObjectInputStream.
 * 
 * @see #writeObject(ObjectOutputStream)
 * @param in where to read the Element from.
 * @throws IOException if there is a reading problem.
 * @throws ClassNotFoundException when a class cannot be found
 */
private void readObject(final ObjectInputStream in)
    throws IOException, ClassNotFoundException {
  in.defaultReadObject();
  
  content = new ContentList(this);
  int nss = in.readInt();
  
  while (--nss >= 0) {
    addNamespaceDeclaration((Namespace)in.readObject());
  }
  
  int ats = in.readInt();
  while (--ats >= 0) {
    setAttribute((Attribute)in.readObject());
  }
  
  int cs = in.readInt();
  while (--cs >= 0) {
    addContent((Content)in.readObject());
  }
}

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

private static final Element processElement(final JDOMFactory factory,
    final StartElement event) {
  final QName qname = event.getName();
  final Element element = factory.element(qname.getLocalPart(),
      Namespace.getNamespace(qname.getPrefix(), qname.getNamespaceURI()));
  // Handle attributes
  for (final Iterator<?> it = event.getAttributes();
      it.hasNext(); ) {
    final javax.xml.stream.events.Attribute att =
        (javax.xml.stream.events.Attribute)it.next();
    final QName aqname = att.getName();
    final Namespace attNs = Namespace.getNamespace(aqname.getPrefix(),
        aqname.getNamespaceURI());
    factory.setAttribute(element, factory.attribute(
        aqname.getLocalPart(), att.getValue(),
        AttributeType.getAttributeType(att.getDTDType()), attNs));
  }
  for (final Iterator<?> it = event.getNamespaces(); it.hasNext();) {
    final javax.xml.stream.events.Namespace ns =
        (javax.xml.stream.events.Namespace)it.next();
    element.addNamespaceDeclaration(Namespace.getNamespace(
        ns.getPrefix(), ns.getNamespaceURI()));
  }
  return element;
}

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

private static final Element processElement(final JDOMFactory factory, 
    final XMLStreamReader reader) {
  final Element element = factory.element(reader.getLocalName(),
      Namespace.getNamespace(reader.getPrefix(), 
          reader.getNamespaceURI()));
  // Handle attributes
  for (int i=0, len=reader.getAttributeCount(); i<len; i++) {
    factory.setAttribute(element, factory.attribute(
        reader.getAttributeLocalName(i),
        reader.getAttributeValue(i), 
        AttributeType.getAttributeType(reader.getAttributeType(i)),
        Namespace.getNamespace(reader.getAttributePrefix(i),
            reader.getAttributeNamespace(i))));
  }
  // Handle Namespaces
  for (int i = 0, len = reader.getNamespaceCount(); i < len; i++) {
    element.addNamespaceDeclaration(Namespace.getNamespace(
        reader.getNamespacePrefix(i), reader.getNamespaceURI(i)));
  }
  return element;
}

代码示例来源:origin: rometools/rome

protected void generateModuleNamespaceDefs(final Element root) {
  for (final Namespace allModuleNamespace : allModuleNamespaces) {
    root.addNamespaceDeclaration(allModuleNamespace);
  }
}

代码示例来源:origin: org.opencadc/cadc-uws

public Element getParametersRootElement(List<Parameter> params) {
  Element root = getParameters(params);
  root.addNamespaceDeclaration(UWS.NS);
  root.addNamespaceDeclaration(UWS.XLINK_NS);
  root.setAttribute(JobAttribute.VERSION.getAttributeName(), UWS.XSD_VERSION);
  return root;
}

代码示例来源:origin: rometools/rome

protected Element createRootElement(final Channel channel) {
  final Element root = new Element("RDF", getRDFNamespace());
  root.addNamespaceDeclaration(getFeedNamespace());
  root.addNamespaceDeclaration(getRDFNamespace());
  root.addNamespaceDeclaration(getContentNamespace());
  generateModuleNamespaceDefs(root);
  return root;
}

代码示例来源:origin: metafacture/metafacture-core

@Override
public void startRecord(final String identifier) {
  assert !isClosed();
  currentElement = createElement(rootTagName);
  for (Namespace namespace : namespaces.values()) {
    currentElement.addNamespaceDeclaration(namespace);
  }
  document = new Document(currentElement);
}

代码示例来源:origin: edu.ucar/netcdf

private void writeOneEntry( InvDataset ds, OutputStream out, StringBuffer mess) throws IOException {
 Element rootElem = new Element("DIF", defNS);
 Document doc = new Document(rootElem);
 writeDataset( ds, rootElem, mess);
 rootElem.addNamespaceDeclaration(defNS);
 rootElem.addNamespaceDeclaration(XMLEntityResolver.xsiNS);
 rootElem.setAttribute("schemaLocation", defNS.getURI()+" "+schemaLocation, XMLEntityResolver.xsiNS);
 // Output the document, use standard formatter
 XMLOutputter fmt = new XMLOutputter( Format.getPrettyFormat());
 fmt.output( doc, out);
}

代码示例来源:origin: edu.ucar/cdm

private void writeOneEntry( InvDataset ds, OutputStream out, StringBuilder mess) throws IOException {
 Element rootElem = new Element("DIF", defNS);
 Document doc = new Document(rootElem);
 writeDataset( ds, rootElem, mess);
 rootElem.addNamespaceDeclaration(defNS);
 rootElem.addNamespaceDeclaration(XMLEntityResolver.xsiNS);
 rootElem.setAttribute("schemaLocation", defNS.getURI()+" "+schemaLocation, XMLEntityResolver.xsiNS);
 // Output the document, use standard formatter
 XMLOutputter fmt = new XMLOutputter( Format.getPrettyFormat());
 fmt.output( doc, out);
}

代码示例来源:origin: rometools/rome

protected Element createRootElement(final Feed feed) {
  final Element root = new Element("feed", getFeedNamespace());
  root.addNamespaceDeclaration(getFeedNamespace());
  // Attribute version = new Attribute("version", getVersion());
  // root.setAttribute(version);
  final String xmlBase = feed.getXmlBase();
  if (xmlBase != null) {
    root.setAttribute("base", xmlBase, Namespace.XML_NAMESPACE);
  }
  generateModuleNamespaceDefs(root);
  return root;
}

代码示例来源:origin: com.rometools/rome

protected Element createRootElement(final Feed feed) {
  final Element root = new Element("feed", getFeedNamespace());
  root.addNamespaceDeclaration(getFeedNamespace());
  // Attribute version = new Attribute("version", getVersion());
  // root.setAttribute(version);
  final String xmlBase = feed.getXmlBase();
  if (xmlBase != null) {
    root.setAttribute("base", xmlBase, Namespace.XML_NAMESPACE);
  }
  generateModuleNamespaceDefs(root);
  return root;
}

代码示例来源:origin: rometools/rome

@Override
protected Element createRootElement(final Channel channel) {
  final Element root = new Element("rss", getFeedNamespace());
  final Attribute version = new Attribute("version", getVersion());
  root.setAttribute(version);
  root.addNamespaceDeclaration(getContentNamespace());
  generateModuleNamespaceDefs(root);
  return root;
}

代码示例来源:origin: rometools/rome

protected Element createRootElement(final Feed feed) {
  final Element root = new Element("feed", getFeedNamespace());
  root.addNamespaceDeclaration(getFeedNamespace());
  final Attribute version = new Attribute("version", getVersion());
  root.setAttribute(version);
  generateModuleNamespaceDefs(root);
  return root;
}

代码示例来源:origin: Unidata/thredds

private void writeOneItem( InvDataset ds, OutputStream out) throws IOException {
 Element rootElem = new Element("itemRecord", defNS);
 Document doc = new Document(rootElem);
 writeDataset( ds, rootElem);
 rootElem.addNamespaceDeclaration(XMLEntityResolver.xsiNS);
 // rootElem.setAttribute("schemaLocation", schemaLocationLocal, XMLEntityResolver.xsiNS);
 rootElem.setAttribute("schemaLocation", defNS.getURI()+" "+schemaLocation, XMLEntityResolver.xsiNS);
 // Output the document, use standard formatter
 //XMLOutputter fmt = new XMLOutputter("  ", true);
 XMLOutputter fmt = new XMLOutputter( Format.getPrettyFormat());
 fmt.output( doc, out);
}

代码示例来源:origin: edu.ucar/netcdf

private void writeOneItem( InvDataset ds, OutputStream out) throws IOException {
 Element rootElem = new Element("dc", defNS);
 Document doc = new Document(rootElem);
 writeDataset( ds, rootElem);
 rootElem.addNamespaceDeclaration(XMLEntityResolver.xsiNS);
 // rootElem.setAttribute("schemaLocation", schemaLocation, XMLEntityResolver.xsiNS);
 rootElem.setAttribute("schemaLocation", defNS.getURI()+" "+schemaLocation, XMLEntityResolver.xsiNS);
 // Output the document, use standard formatter
 //XMLOutputter fmt = new XMLOutputter("  ", true);
 XMLOutputter fmt = new XMLOutputter( Format.getPrettyFormat());
 fmt.output( doc, out);
}

相关文章

微信公众号

最新文章

更多