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

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

本文整理了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

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

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

  1. public String marshall(Html html) throws Exception {
  2. StringWriter writer = new StringWriter();
  3. xmlContext = new XMLContext();
  4. Mapping mapping = xmlContext.createMapping();
  5. mapping.loadMapping(coreResources.getURL("xformMapping.xml"));
  6. xmlContext.addMapping(mapping);
  7. Marshaller marshaller = xmlContext.createMarshaller();
  8. marshaller.setNamespaceMapping("h", "http://www.w3.org/1999/xhtml");
  9. marshaller.setNamespaceMapping("jr", "http://openrosa.org/javarosa");
  10. marshaller.setNamespaceMapping("xsd", "http://www.w3.org/2001/XMLSchema");
  11. marshaller.setNamespaceMapping("ev", "http://www.w3.org/2001/xml-events");
  12. marshaller.setNamespaceMapping("", "http://www.w3.org/2002/xforms");
  13. marshaller.setNamespaceMapping("enk", "http://enketo.org/xforms");
  14. marshaller.setNamespaceMapping("oc", "http://openclinica.org/xforms");
  15. marshaller.setWriter(writer);
  16. marshaller.marshal(html);
  17. String xform = writer.toString();
  18. return xform;
  19. }

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

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

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

  1. /**
  2. * Serializes the mapping to the given writer.
  3. *
  4. * @param writer the Writer to serialize the mapping to
  5. * @throws MappingException if writing the mapping information fails
  6. */
  7. public void write(final Writer writer) throws MappingException {
  8. Marshaller marshal;
  9. MappingRoot mapping;
  10. Enumeration enumeration;
  11. try {
  12. mapping = new MappingRoot();
  13. mapping.setDescription("Castor generated mapping file");
  14. enumeration = _mappings.elements();
  15. while (enumeration.hasMoreElements()) {
  16. mapping.addClassMapping((ClassMapping) enumeration.nextElement());
  17. }
  18. marshal = new Marshaller(writer);
  19. marshal.setNamespaceMapping(null, "http://castor.exolab.org/");
  20. marshal.setNamespaceMapping("cst", "http://castor.exolab.org/");
  21. marshal.marshal(mapping);
  22. } catch (Exception except) {
  23. throw new MappingException(except);
  24. }
  25. } // -- write

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

  1. /**
  2. * Serializes the mapping to the given writer.
  3. *
  4. * @param writer
  5. * the Writer to serialize the mapping to
  6. * @throws MappingException if writing the mapping information fails
  7. */
  8. public void write(final Writer writer) throws MappingException {
  9. Marshaller marshal;
  10. MappingRoot mapping;
  11. Enumeration enumeration;
  12. try {
  13. mapping = new MappingRoot();
  14. mapping.setDescription("Castor generated mapping file");
  15. enumeration = _mappings.elements();
  16. while (enumeration.hasMoreElements()) {
  17. mapping.addClassMapping((ClassMapping) enumeration.nextElement());
  18. }
  19. marshal = new Marshaller(writer);
  20. marshal.setNamespaceMapping(null, "http://castor.exolab.org/");
  21. marshal.setNamespaceMapping("cst", "http://castor.exolab.org/");
  22. marshal.marshal(mapping);
  23. } catch (Exception except) {
  24. throw new MappingException(except);
  25. }
  26. } // -- write

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

  1. /**
  2. * Template method that allows for customizing of the given Castor {@link Marshaller}.
  3. * <p/>
  4. * Default implementation invokes {@link Marshaller#setValidation(boolean)} with the property set on this
  5. * marshaller, and calls {@link Marshaller#setNamespaceMapping(String, String)} with the {@linkplain
  6. * #setNamespaceMappings(java.util.Properties) namespace mappings}.
  7. */
  8. protected void customizeMarshaller(Marshaller marshaller) {
  9. marshaller.setValidation(isValidating());
  10. marshaller.setSuppressNamespaces(isSuppressNamespaces());
  11. marshaller.setSuppressXSIType(isSuppressXsiType());
  12. Properties namespaceMappings = getNamespaceMappings();
  13. if (namespaceMappings != null) {
  14. for (Iterator iterator = namespaceMappings.keySet().iterator(); iterator.hasNext();) {
  15. String prefix = (String) iterator.next();
  16. String uri = namespaceMappings.getProperty(prefix);
  17. marshaller.setNamespaceMapping(prefix, uri);
  18. }
  19. }
  20. }

相关文章