org.jdom2.Namespace类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(119)

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

Namespace介绍

[英]An XML namespace representation, as well as a factory for creating XML namespace objects. All methods on Namespace (including #getNamespace(String) and #getNamespace(String,String)) are thread-safe.

See NamespaceAware for additional notes on how Namespaces are 'in-scope' in JDOM content, and how those in-scope Namespaces are accessed.
[中]XML命名空间表示,以及用于创建XML命名空间对象的工厂。命名空间上的所有方法(包括#getNamespace(String)和#getNamespace(String,String))都是线程安全的。
有关如何在JDOM内容中“在范围内”使用名称空间以及如何访问范围内名称空间的更多说明,请参见NamespaceAware。

代码示例

代码示例来源: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

private static boolean compareAttributeAwareConfigTag(Element e, AttributeAwareConfigTag attributeAwareConfigTag) {
  return attributeAwareConfigTag.value().equals(e.getName()) &&
      attributeAwareConfigTag.attributeValue().equals(e.getAttributeValue(attributeAwareConfigTag.attribute())) &&
      e.getNamespace().getURI().equals(attributeAwareConfigTag.namespaceURI());
}

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

@Override
  public String toString() {
    return ns.getPrefix() + "=" + ns.getURI();
  }
}

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

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: senbox-org/s2tbx

Element web_app = jdomDoc.getRootElement();
String maskEpsg = "";
Namespace gml = Namespace.getNamespace("http://www.opengis.net/gml/3.2");
Namespace eop = Namespace.getNamespace("http://www.opengis.net/eop/2.0");
List<Element> targeted = web_app.getChildren("boundedBy", gml);
if(!targeted.isEmpty()) {
  Element aEnvelope = targeted.get(0).getChild("Envelope", gml);
  if(aEnvelope != null) {
    maskEpsg = aEnvelope.getAttribute("srsName").getValue();
  if (!web_app_content.getCType().equals(CType.Text) && !web_app_content.getCType().equals(CType.Comment))
    boolean withGml = (web_app_content.getNamespacesInScope().get(0).getPrefix().contains("gml"));
    if(withGml)
      boolean parentNotGml = !(web_app_content.getParentElement().getNamespace().getPrefix().contains("gml"));
      if(parentNotGml)
          if(attr != null)
            polygonId = attr.getValue();
            if(polygonId.indexOf('.') != -1)
        Document newDoc = new Document(capturedElement.clone().detach());

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

private Transfer parseTransfer(Document document, String targetScheme)
  throws URISyntaxException
  Element root = document.getRootElement();
  Namespace vosNS = root.getNamespace();
  Attribute versionAttr = root.getAttribute("version");
  if (VOSPACE_NS_20.equals(vosNS.getURI())) {
    version = VOS.VOSPACE_20;
    if (versionAttr != null && VOSPACE_MINOR_VERSION_21.equals(versionAttr.getValue())) {
      version = VOS.VOSPACE_21;
    throw new IllegalArgumentException("unexpected VOSpace namespace: " + vosNS.getURI());
  URI target = new URI(root.getChildText("target", vosNS));

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

@Override
public boolean isMyType(final Document document) {
  final Element rssRoot = document.getRootElement();
  final Namespace defaultNS = rssRoot.getNamespace();
  return defaultNS != null && defaultNS.equals(getAtomNamespace());
}

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

ch.startPrefixMapping(ns.getPrefix(), ns.getURI());
  if (out.isDeclareNamespaces()) {
    String prefix = ns.getPrefix();
    if (prefix.equals("")) {
      atts.addAttribute("", "", "xmlns", "CDATA", ns.getURI());
    } else {
      atts.addAttribute("", "", "xmlns:" + ns.getPrefix(),
          "CDATA", ns.getURI());
if (element.hasAttributes()) {
  for (Attribute a : element.getAttributes()) {
    if (!a.isSpecified() && fstack.isSpecifiedAttributesOnly()) {
      continue;
    atts.addAttribute(a.getNamespaceURI(), a.getName(),
        a.getQualifiedName(),
        getAttributeTypeName(a.getAttributeType()),
ch.startElement(element.getNamespaceURI(), element.getName(),
    element.getQualifiedName(), atts);
  ch.endPrefixMapping(ns.getPrefix());

代码示例来源:origin: org.mycore/mycore-pi

private void changeToTestDOI(Document metadata) {
  XPathExpression<Element> compile = XPathFactory.instance().compile(
    "//datacite:identifier[@identifierType='DOI']", Filters.element(), null,
    Namespace.getNamespace("datacite", metadata.getRootElement().getNamespace().getURI()));
  Element element = compile.evaluateFirst(metadata);
  MCRDigitalObjectIdentifier doi = new MCRDOIParser()
    .parse(element.getText())
    .orElseThrow(() -> new MCRException("Datacite Document contains invalid DOI!"));
  String testDOI = doi.toTestPrefix().asString();
  element.setText(testDOI);
}

代码示例来源:origin: org.opencadc/caom2

if (cur != null)
  Attribute type = cur.getAttribute("type", xsiNamespace);
  String tval = type.getValue();
  String extype = namespace.getPrefix() + ":" + Polygon.class.getSimpleName();
  if ( extype.equals(tval) )
    Element ves = cur.getChild("vertices", namespace);
    for (Element ve : ves.getChildren()) // only vertex

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

try {
  Namespace ns = element.getNamespace();
  Iterator<Attribute> ait = element.hasAttributes() ?
      element.getAttributes().iterator() :
        null;
  if (ns == Namespace.NO_NAMESPACE) {
        new AttIterator(ait, eventfactory, fstack.isSpecifiedAttributesOnly()), 
        new NSIterator(nstack.addedForward().iterator(), eventfactory)));
  } else if ("".equals(ns.getPrefix())) {
    out.add(eventfactory.createStartElement("", ns.getURI(), element.getName(), 
        new AttIterator(ait, eventfactory, fstack.isSpecifiedAttributesOnly()), 
        new NSIterator(nstack.addedForward().iterator(), eventfactory)));
  } else {
    out.add(eventfactory.createStartElement(ns.getPrefix(), ns.getURI(), element.getName(), 
        new AttIterator(ait, eventfactory, fstack.isSpecifiedAttributesOnly()), 
        new NSIterator(nstack.addedForward().iterator(), eventfactory)));

代码示例来源:origin: org.opencadc/caom2

Element root = document.getRootElement();
Namespace namespace = root.getNamespace();
log.debug("obs namespace uri: " + namespace.getURI());
log.debug("obs namespace prefix: " + namespace.getPrefix());
if ( XmlConstants.CAOM2_0_NAMESPACE.equals(namespace.getURI()) )
  rc.docVersion = 20;
else if ( XmlConstants.CAOM2_1_NAMESPACE.equals(namespace.getURI()) )
  rc.docVersion = 21;
else if ( XmlConstants.CAOM2_2_NAMESPACE.equals(namespace.getURI()) )
  rc.docVersion = 22;
Attribute type = root.getAttribute("type", xsiNamespace);
String tval = type.getValue();
String simple = namespace.getPrefix() + ":" +  SimpleObservation.class.getSimpleName();
String comp = namespace.getPrefix() + ":" +  CompositeObservation.class.getSimpleName();
if ( simple.equals(tval) )

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

private boolean isGetCoverageWcsDoc(String url) throws JDOMException, IOException {
 byte[] result = TestOnLocalServer.getContent(url+baloney+"&request=GetCapabilities", 200, ContentType.xml);
 Reader in = new StringReader( new String(result, CDM.utf8Charset));
 SAXBuilder sb = new SAXBuilder();
 Document doc = sb.build(in);
 boolean isName =  doc.getRootElement().getName().equals("WCS_Capabilities");
 boolean isNamespace = doc.getRootElement().getNamespaceURI().equals(NS_WCS.getURI());
 return (isName && isNamespace);
}

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

private boolean hasElementsFrom(final Element root, final Namespace namespace) {
  boolean hasElements = false;
  for (final Element child : root.getChildren()) {
    final Namespace childNamespace = child.getNamespace();
    if (namespace.equals(childNamespace)) {
      hasElements = true;
      break;
    }
  }
  return hasElements;
}

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

Element eleColumn = new Element("column");
addChild(eleColumn, "name", cd.getColumnName());
addChild(eleColumn, "description", cd.description);
  if (eleDt != null)
    Attribute attType = new Attribute("type", vod.getPrefix() + ":VOTableType", xsi);
    eleDt.setAttribute(attType);
    if (tt.arraysize != null)
      eleDt.setAttribute("arraysize", tt.arraysize);
    if (tt.xtype != null)
      eleDt.setAttribute("extendedType", tt.xtype);
  if (eleDt != null)
    Attribute attType = new Attribute("type", vod.getPrefix() + ":TAPType", xsi);
    eleDt.setAttribute(attType);
    if (tt.arraysize != null && !tt.isVarSize()) // assume single digit

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

final String space = element.getAttributeValue("space",
    Namespace.XML_NAMESPACE);
    element.getNamespaceURI(), element.getQualifiedName());
    continue;
  ret.setAttribute(getXmlnsTagFor(ns), ns.getURI());

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

@Test
public void shouldAddPluginNamespaceToPassedInElement() throws MalformedURLException {
  ConfigElementImplementationRegistry registry = new ConfigElementImplementationRegistry(pluginExtns);
  registry.xsdFor(PluginTestUtil.bundleCtxWithHeaders(m(PluginNamespace.XSD_NAMESPACE_PREFIX, "something", PluginNamespace.XSD_NAMESPACE_URI, "uri")), new File("file:///tmp/foo").toURI().toURL());
  registry.xsdFor(PluginTestUtil.bundleCtxWithHeaders(m(PluginNamespace.XSD_NAMESPACE_PREFIX, "second", PluginNamespace.XSD_NAMESPACE_URI, "uri-1")), new File("file:///tmp/foo1").toURI().toURL());
  Element foo = new Element("foo");
  registry.registerNamespacesInto(foo);
  assertThat(foo.getNamespace("something"), is(Namespace.getNamespace("something", "uri")));
  assertThat(foo.getNamespace("second"), is(Namespace.getNamespace("second", "uri-1")));
}

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

@Override
public javax.xml.stream.events.Attribute next() {
  final Attribute att = source.next();
  final Namespace ns = att.getNamespace();
  if (ns == Namespace.NO_NAMESPACE) {
    return fac.createAttribute(att.getName(), att.getValue());
  }
  return fac.createAttribute(ns.getPrefix(), ns.getURI(), 
      att.getName(), att.getValue());
}

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

public static boolean compare(Element e, Class<?> implementation, ConfigCache configCache) {
  final AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(implementation, AttributeAwareConfigTag.class);
  if (attributeAwareConfigTag != null) {
    return compareAttributeAwareConfigTag(e, attributeAwareConfigTag);
  }
  ConfigTag configTag = configTag(implementation, configCache);
  return configTag.value().equals(e.getName()) && e.getNamespace().getURI().equals(configTag.namespaceURI());
}

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

private Element child(Element e, ConfigTag tag) {
  return e.getChild(tag.value(), Namespace.getNamespace(tag.namespacePrefix(), tag.namespaceURI()));
}

相关文章