org.exolab.castor.xml.Marshaller.setNamespaceMapping()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(145)

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

Marshaller.setNamespaceMapping介绍

[英]Sets the mapping for the given Namespace prefix
[中]给定名称空间前缀集的映射

代码示例

代码示例来源:origin: stackoverflow.com

Marshaller  casreactmp = new Marshaller(handler);
     casreactmp.setNamespaceMapping("dc", "http://purl.org/dc/elements/1.1/");

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

public String marshall(Html html) throws Exception {
  StringWriter writer = new StringWriter();
  xmlContext = new XMLContext();
  Mapping mapping = xmlContext.createMapping();
  mapping.loadMapping(coreResources.getURL("xformMapping.xml"));
  xmlContext.addMapping(mapping);
  Marshaller marshaller = xmlContext.createMarshaller();
  marshaller.setNamespaceMapping("h", "http://www.w3.org/1999/xhtml");
  marshaller.setNamespaceMapping("jr", "http://openrosa.org/javarosa");
  marshaller.setNamespaceMapping("xsd", "http://www.w3.org/2001/XMLSchema");
  marshaller.setNamespaceMapping("ev", "http://www.w3.org/2001/xml-events");
  marshaller.setNamespaceMapping("", "http://www.w3.org/2002/xforms");
  marshaller.setNamespaceMapping("enk", "http://enketo.org/xforms");
  marshaller.setNamespaceMapping("oc", "http://openclinica.org/xforms");
  marshaller.setWriter(writer);
  marshaller.marshal(html);
  String xform = writer.toString();
  return xform;
}

代码示例来源:origin: com.github.muff1nman.chameleon/playlist-rss

@Override
public void writeTo(final OutputStream out, final String encoding) throws Exception
{
  // Marshal the RSS document.
  final StringWriter writer = new StringWriter();
  final XmlSerializer serializer = XmlSerializer.getMapping("chameleon/rss"); // May throw Exception.
  // Specifies whether XML documents (as generated at marshalling) should use indentation or not. Default is false.
  serializer.getMarshaller().setProperty("org.exolab.castor.indent", "true");
  //serializer.getMarshaller().setNamespaceMapping("", "http://purl.org/rss/1.0/modules/content/");
  serializer.getMarshaller().setNamespaceMapping("media", "http://search.yahoo.com/mrss/");
  serializer.marshal(_rss, writer, false); // May throw Exception.
  String enc = encoding;
  if (enc == null)
  {
    enc = "UTF-8";
  }
  final byte[] bytes = writer.toString().getBytes(enc); // May throw UnsupportedEncodingException.
  out.write(bytes); // Throws NullPointerException if out is null. May throw IOException.
  out.flush(); // May throw IOException.
}

代码示例来源:origin: org.codehaus.castor/castor-xml

/**
 * Serializes the mapping to the given writer.
 * 
 * @param writer the Writer to serialize the mapping to
 * @throws MappingException if writing the mapping information fails
 */
public void write(final Writer writer) throws MappingException {
 Marshaller marshal;
 MappingRoot mapping;
 Enumeration enumeration;
 try {
  mapping = new MappingRoot();
  mapping.setDescription("Castor generated mapping file");
  enumeration = _mappings.elements();
  while (enumeration.hasMoreElements()) {
   mapping.addClassMapping((ClassMapping) enumeration.nextElement());
  }
  marshal = new Marshaller(writer);
  marshal.setNamespaceMapping(null, "http://castor.exolab.org/");
  marshal.setNamespaceMapping("cst", "http://castor.exolab.org/");
  marshal.marshal(mapping);
 } catch (Exception except) {
  throw new MappingException(except);
 }
} // -- write

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

/**
 * Serializes the mapping to the given writer.
 * 
 * @param writer
 *            the Writer to serialize the mapping to
 * @throws MappingException if writing the mapping information fails
 */
public void write(final Writer writer) throws MappingException {
  Marshaller marshal;
  MappingRoot mapping;
  Enumeration enumeration;
  try {
    mapping = new MappingRoot();
    mapping.setDescription("Castor generated mapping file");
    enumeration = _mappings.elements();
    while (enumeration.hasMoreElements()) {
      mapping.addClassMapping((ClassMapping) enumeration.nextElement());
    }
    marshal = new Marshaller(writer);
    marshal.setNamespaceMapping(null, "http://castor.exolab.org/");
    marshal.setNamespaceMapping("cst", "http://castor.exolab.org/");
    marshal.marshal(mapping);
  } catch (Exception except) {
    throw new MappingException(except);
  }
} // -- write

代码示例来源:origin: org.springframework.ws/spring-oxm

/**
 * Template method that allows for customizing of the given Castor {@link Marshaller}.
 * <p/>
 * Default implementation invokes {@link Marshaller#setValidation(boolean)} with the property set on this
 * marshaller, and calls {@link Marshaller#setNamespaceMapping(String, String)} with the {@linkplain
 * #setNamespaceMappings(java.util.Properties) namespace mappings}.
 */
protected void customizeMarshaller(Marshaller marshaller) {
  marshaller.setValidation(isValidating());
  marshaller.setSuppressNamespaces(isSuppressNamespaces());
  marshaller.setSuppressXSIType(isSuppressXsiType());
  Properties namespaceMappings = getNamespaceMappings();
  if (namespaceMappings != null) {
    for (Iterator iterator = namespaceMappings.keySet().iterator(); iterator.hasNext();) {
      String prefix = (String) iterator.next();
      String uri = namespaceMappings.getProperty(prefix);
      marshaller.setNamespaceMapping(prefix, uri);
    }
  }
}

相关文章