gpt4 book ai didi

org.restlet.ext.xml.XmlWriter类的使用及代码示例

转载 作者:知者 更新时间:2024-03-21 15:13:05 27 4
gpt4 key购买 nike

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

XmlWriter介绍

[英]XML writer doing the opposite work of a SAX-based XML reader. The implementation is based on the work of David Megginson, the creator of SAX who placed the original code in the public domain.

This class can be used by itself or as part of a SAX event stream: it takes as input a series of SAX2 ContentHandler events and uses the information in those events to write an XML document. Since this class is a filter, it can also pass the events on down a filter chain for further processing (you can use the XmlWriter to take a snapshot of the current state at any point in a filter chain), and it can be used directly as a ContentHandler for a SAX2 XMLReader.

The client creates a document by invoking the methods for standard SAX2 events, always beginning with the #startDocument method and ending with the #endDocument method. There are convenience methods provided so that clients to not have to create empty attribute lists or provide empty strings as parameters; for example, the method invocation

w.startElement("foo");

is equivalent to the regular SAX2 ContentHandler method

w.startElement("", "foo", "", new AttributesImpl());

Except that it is more efficient because it does not allocate a new empty attribute list each time. The following code will send a simple XML document to standard output:

XmlWriter w = new XmlWriter(); 
w.startDocument(); 
w.startElement("greeting"); 
w.characters("Hello, world!"); 
w.endElement("greeting"); 
w.endDocument();

The resulting document will look like this:

<?xml version="1.0" standalone='yes'?> 
<greeting>Hello, world!</greeting>

In fact, there is an even simpler convenience method, dataElement, designed for writing elements that contain only character data, so the code to generate the document could be shortened to

XmlWriter w = new XmlWriter(); 
w.startDocument(); 
w.dataElement("greeting", "Hello, world!"); 
w.endDocument();

Whitespace

According to the XML Recommendation, all whitespace in an XML document is potentially significant to an application, so this class never adds newlines or indentation. If you insert three elements in a row, as in

w.dataElement("item", "1"); 
w.dataElement("item", "2"); 
w.dataElement("item", "3");

you will end up with

<item>1</item><item>3</item><item>3</item>

You need to invoke one of the characters methods explicitly to add newlines or indentation. Alternatively, you can use the data format mode (set the "dataFormat" property) which is optimized for writing purely data-oriented (or field-oriented) XML, and does automatic linebreaks and indentation (but does not support mixed content properly). See details below.

Namespace Support

The writer contains extensive support for XML Namespaces, so that a client application does not have to keep track of prefixes and supply xmlns attributes. By default, the XML writer will generate Namespace declarations in the form _NS1, _NS2, etc., wherever they are needed, as in the following example:

w.startDocument(); 
w.emptyElement("http://www.foo.com/ns/", "foo"); 
w.endDocument();

The resulting document will look like this:

<?xml version="1.0" standalone='yes'?> 
<_NS1:foo xmlns:_NS1="http://www.foo.com/ns/"/>

In many cases, document authors will prefer to choose their own prefixes rather than using the (ugly) default names. The XML writer allows two methods for selecting prefixes:

  1. the qualified name
  2. the #setPrefix method.

Whenever the XML writer finds a new Namespace URI, it checks to see if a qualified (prefixed) name is also available; if so it attempts to use the name's prefix (as long as the prefix is not already in use for another Namespace URI).

Before writing a document, the client can also pre-map a prefix to a Namespace URI with the setPrefix method:

w.setPrefix("http://www.foo.com/ns/", "foo"); 
w.startDocument(); 
w.emptyElement("http://www.foo.com/ns/", "foo"); 
w.endDocument();

The resulting document will look like this:

<?xml version="1.0" standalone='yes'?> 
<foo:foo xmlns:foo="http://www.foo.com/ns/"/>

The default Namespace simply uses an empty string as the prefix:

w.setPrefix("http://www.foo.com/ns/", ""); 
w.startDocument(); 
w.emptyElement("http://www.foo.com/ns/", "foo"); 
w.endDocument();

The resulting document will look like this:

<?xml version="1.0" standalone='yes'?> 
<foo xmlns="http://www.foo.com/ns/"/>

By default, the XML writer will not declare a Namespace until it is actually used. Sometimes, this approach will create a large number of Namespace declarations, as in the following example:

<xml version="1.0" standalone='yes'?> 
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> 
<rdf:Description about="http://www.foo.com/ids/books/12345"> 
<dc:title xmlns:dc="http://www.purl.org/dc/">A Dark Night</dc:title> 
<dc:creator xmlns:dc="http://www.purl.org/dc/">Jane Smith</dc:title> 
<dc:date xmlns:dc="http://www.purl.org/dc/">2000-09-09</dc:title> 
</rdf:Description> 
</rdf:RDF>

The "rdf" prefix is declared only once, because the RDF Namespace is used by the root element and can be inherited by all of its descendants; the "dc" prefix, on the other hand, is declared three times, because no higher element uses the Namespace. To solve this problem, you can instruct the XML writer to predeclare Namespaces on the root element even if they are not used there:

w.forceNSDecl("http://www.purl.org/dc/");

Now, the "dc" prefix will be declared on the root element even though it's not needed there, and can be inherited by its descendants:

<xml version="1.0" standalone='yes'?> 
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
xmlns:dc="http://www.purl.org/dc/"> 
<rdf:Description about="http://www.foo.com/ids/books/12345"> 
<dc:title>A Dark Night</dc:title> 
<dc:creator>Jane Smith</dc:title> 
<dc:date>2000-09-09</dc:title> 
</rdf:Description> 
</rdf:RDF>

This approach is also useful for declaring Namespace prefixes that be used by qualified names appearing in attribute values or character data.

Data Format

This mode, enabled by the "dataFormat" property, pretty-prints field-oriented XML without mixed content. All added indentation and newlines will be passed on down the filter chain (if any).

In general, all whitespace in an XML document is potentially significant, so a general-purpose XML writing tool cannot add newlines or indentation.

There is, however, a large class of XML documents where information is strictly fielded: each element contains either character data or other elements, but not both. For this special case, it is possible for a writing tool to provide automatic indentation and newlines without requiring extra work from the user. Note that this class will likely not yield appropriate results for document-oriented XML like XHTML pages, which mix character data and elements together.

This writer mode will automatically place each start tag on a new line, optionally indented if an indent step is provided (by default, there is no indentation). If an element contains other elements, the end tag will also appear on a new line with leading indentation. Consider, for example, the following code:

XmlWriter w = new XmlWriter(); 
w.setDataFormat(true); 
w.setIndentStep(2); 
w.startDocument(); 
w.startElement("Person"); 
w.dataElement("name", "Jane Smith"); 
w.dataElement("date-of-birth", "1965-05-23"); 
w.dataElement("citizenship", "US"); 
w.endElement("Person"); 
w.endDocument();

This code will produce the following document:

<?xml version="1.0" standalone='yes'?> 
<Person> 
<name>Jane Smith</name> 
<date-of-birth>1965-05-23</date-of-birth> 
<citizenship>US</citizenship> 
</Person>

[中]XML编写器的工作与基于SAX的XML读取器的工作相反。该实现基于SAX的创建者David Megginson的工作,他将原始代码放在公共域中。
此类可以单独使用,也可以作为SAX事件流的一部分使用:它接受一系列SAX2 ContentHandler事件作为输入,并使用这些事件中的信息编写XML文档。由于该类是一个过滤器,它还可以将事件向下传递到过滤器链以进行进一步处理(可以使用XmlWriter在过滤器链中的任意点拍摄当前状态的快照),并且可以直接用作SAX2 XMLReader的ContentHandler。
客户端通过调用标准SAX2事件的方法创建文档,始终以#startDocument方法开始,以#endDocument方法结束。提供了一些方便的方法,以便客户端不必创建空属性列表或提供空字符串作为参数;例如,方法调用

w.startElement("foo");

相当于常规的SAX2 ContentHandler方法

w.startElement("", "foo", "", new AttributesImpl());

但它更高效,因为它不会每次分配一个新的空属性列表。以下代码将向标准输出发送一个简单的XML文档:

XmlWriter w = new XmlWriter(); 
w.startDocument(); 
w.startElement("greeting"); 
w.characters("Hello, world!"); 
w.endElement("greeting"); 
w.endDocument();

生成的文档如下所示:

<?xml version="1.0" standalone='yes'?> 
<greeting>Hello, world!</greeting>

事实上,还有一种更简单的方便方法dataElement,用于编写只包含字符数据的元素,因此生成文档的代码可以缩短为

XmlWriter w = new XmlWriter(); 
w.startDocument(); 
w.dataElement("greeting", "Hello, world!"); 
w.endDocument();

空白
根据XML建议,XML文档中的all空格对应用程序可能很重要,所以这个类从不添加换行符或缩进。如果在一行中插入三个元素,如

w.dataElement("item", "1"); 
w.dataElement("item", "2"); 
w.dataElement("item", "3");

你最终会得到

<item>1</item><item>3</item><item>3</item>

您需要显式调用其中一个characters方法来添加换行符或缩进。或者,您可以使用数据格式模式(设置“dataFormat”属性),该模式针对编写纯面向数据(或面向字段)的XML进行了优化,并执行自动换行和缩进(但不正确支持混合内容)。详情见下文。
命名空间支持
writer包含对XML名称空间的广泛支持,因此客户端应用程序不必跟踪前缀并提供xmlns属性。默认情况下,XML编写器将在需要时以_NS1、_NS2等形式生成名称空间声明,如下例所示:

w.startDocument(); 
w.emptyElement("http://www.foo.com/ns/", "foo"); 
w.endDocument();

生成的文档如下所示:

<?xml version="1.0" standalone='yes'?> 
<_NS1:foo xmlns:_NS1="http://www.foo.com/ns/"/>

在许多情况下,文档作者更愿意选择自己的前缀,而不是使用(难看的)默认名称。XML writer允许两种选择前缀的方法:
1.限定名称
1.#setPrefix方法。
每当XML编写器找到一个新的名称空间URI时,它都会检查是否还有一个限定的(带前缀的)名称可用;如果是这样,它将尝试使用名称的前缀(只要该前缀尚未用于另一个命名空间URI)。
在编写文档之前,客户端还可以使用setPrefix方法将前缀预映射到命名空间URI:

w.setPrefix("http://www.foo.com/ns/", "foo"); 
w.startDocument(); 
w.emptyElement("http://www.foo.com/ns/", "foo"); 
w.endDocument();

生成的文档如下所示:

<?xml version="1.0" standalone='yes'?> 
<foo:foo xmlns:foo="http://www.foo.com/ns/"/>

默认名称空间仅使用空字符串作为前缀:

w.setPrefix("http://www.foo.com/ns/", ""); 
w.startDocument(); 
w.emptyElement("http://www.foo.com/ns/", "foo"); 
w.endDocument();

生成的文档如下所示:

<?xml version="1.0" standalone='yes'?> 
<foo xmlns="http://www.foo.com/ns/"/>

默认情况下,XML编写器在实际使用名称空间之前不会声明名称空间。有时,这种方法会创建大量名称空间声明,如下例所示:

<xml version="1.0" standalone='yes'?> 
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> 
<rdf:Description about="http://www.foo.com/ids/books/12345"> 
<dc:title xmlns:dc="http://www.purl.org/dc/">A Dark Night</dc:title> 
<dc:creator xmlns:dc="http://www.purl.org/dc/">Jane Smith</dc:title> 
<dc:date xmlns:dc="http://www.purl.org/dc/">2000-09-09</dc:title> 
</rdf:Description> 
</rdf:RDF>

“rdf”前缀只声明一次,因为rdf名称空间由根元素使用,并且可以由其所有子元素继承;另一方面,“dc”前缀声明了三次,因为没有更高的元素使用名称空间。为了解决这个问题,可以指示XML编写器在根元素上预先定义名称空间,即使它们在根元素中没有使用:

w.forceNSDecl("http://www.purl.org/dc/");

现在,“dc”前缀将在根元素上声明,即使它在根元素中不需要,并且可以由其子元素继承:

<xml version="1.0" standalone='yes'?> 
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
xmlns:dc="http://www.purl.org/dc/"> 
<rdf:Description about="http://www.foo.com/ids/books/12345"> 
<dc:title>A Dark Night</dc:title> 
<dc:creator>Jane Smith</dc:title> 
<dc:date>2000-09-09</dc:title> 
</rdf:Description> 
</rdf:RDF>

这种方法在声明命名空间前缀时也很有用,这些前缀由属性值或字符数据中出现的限定名使用。
数据格式
这种模式由“dataFormat”属性启用,可以打印面向字段的XML,而不包含混合内容。所有添加的缩进和换行将沿着过滤器链传递(如果有)。
一般来说,XML文档中的所有空白都可能是重要的,因此通用XML编写工具无法添加换行符或缩进。
然而,有一大类XML文档严格地定义了信息:每个元素要么包含字符数据,要么包含其他元素,但不能同时包含两者。对于这种特殊情况,书写工具可以提供自动缩进和换行,而不需要用户做额外的工作。请注意,对于像XHTML页面这样的面向文档的XML,这个类可能不会产生合适的结果,因为XHTML页面将字符数据和元素混合在一起。
此写入器模式将自动将每个开始标记放置在新行上,如果提供缩进步骤,则可以选择缩进(默认情况下,没有缩进)。如果一个元素包含其他元素,结束标记也会出现在一个带有前导缩进的新行上。例如,考虑下面的代码:

XmlWriter w = new XmlWriter(); 
w.setDataFormat(true); 
w.setIndentStep(2); 
w.startDocument(); 
w.startElement("Person"); 
w.dataElement("name", "Jane Smith"); 
w.dataElement("date-of-birth", "1965-05-23"); 
w.dataElement("citizenship", "US"); 
w.endElement("Person"); 
w.endDocument();

此代码将生成以下文档:

<?xml version="1.0" standalone='yes'?> 
<Person> 
<name>Jane Smith</name> 
<date-of-birth>1965-05-23</date-of-birth> 
<citizenship>US</citizenship> 
</Person>

代码示例

代码示例来源:origin: org.restlet.android/org.restlet.ext.atom

/**
 * Writes the representation to a XML writer.
 * 
 * @param writer
 *            The XML writer to write to.
 * @throws IOException
 */
@Override
public void write(XmlWriter writer) throws IOException {
  try {
    writer.forceNSDecl(APP_NAMESPACE, "");
    writer.forceNSDecl(ATOM_NAMESPACE, "atom");
    writer.setDataFormat(true);
    writer.setIndentStep(3);
    writer.startDocument();
    writer.startElement(APP_NAMESPACE, "service");
    for (final Workspace workspace : getWorkspaces()) {
      workspace.writeElement(writer);
    }
    writer.endElement(APP_NAMESPACE, "service");
    writer.endDocument();
  } catch (SAXException se) {
    throw new IOException("Couldn't write the service representation: "
        + se.getMessage());
  }
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.atom

/**
 * Writes the current object as an XML element using the given SAX writer.
 * 
 * @param writer
 *            The SAX writer.
 * @param namespace
 *            The element namespace URI.
 * @param localName
 *            The local name of the element.
 * @throws SAXException
 */
public static void writeElement(XmlWriter writer, Date date,
    String namespace, String localName) throws SAXException {
  if (date != null) {
    writer.startElement(namespace, localName);
    writer.characters(DateUtils.format(date,
        DateUtils.FORMAT_RFC_3339.get(0)));
    writer.endElement(namespace, localName);
  } else {
    writer.emptyElement(namespace, localName);
  }
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.atom

/**
 * Initiates the parsing of a mixed content part of the current document.
 */
private void initiateInlineMixedContent() {
  this.contentDepth = 0;
  StringWriter sw = new StringWriter();
  currentContentWriter = new XmlWriter(sw);
  for (String prefix : this.prefixMappings.keySet()) {
    currentContentWriter.forceNSDecl(this.prefixMappings.get(prefix),
        prefix);
  }
}

代码示例来源:origin: org.restlet/org.restlet.ext.xml

/**
 * Write character data. Pass the event on down the filter chain for further
 * processing.
 * 
 * @param ch
 *            The array of characters to write.
 * @param start
 *            The starting position in the array.
 * @param len
 *            The number of characters to write.
 * @exception org.xml.sax.SAXException
 *                If there is an error writing the characters, or if a
 *                restlet further down the filter chain raises an exception.
 * @see org.xml.sax.ContentHandler#characters
 */
@Override
public void characters(char ch[], int start, int len) throws SAXException {
  characters(isDataFormat(), ch, start, len);
}

代码示例来源:origin: org.restlet.android/org.restlet.ext.xml

/**
 * Force a Namespace declaration with a preferred prefix.
 * <p>
 * This is a convenience method that invokes {@link #setPrefix setPrefix}
 * then {@link #forceNSDecl(java.lang.String) forceNSDecl}.
 * </p>
 * 
 * @param uri
 *            The Namespace URI to declare on the root element.
 * @param prefix
 *            The preferred prefix for the Namespace, or "" for the default
 *            Namespace.
 * @see #setPrefix
 * @see #forceNSDecl(java.lang.String)
 */
public void forceNSDecl(String uri, String prefix) {
  setPrefix(uri, prefix);
  forceNSDecl(uri);
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.xml

public void startElement(String uri, String localName, String qName,
    Attributes atts) throws SAXException {
  if (isDataFormat()) {
    this.stateStack.push(SEEN_ELEMENT);
    this.state = SEEN_NOTHING;
    if (this.depth > 0) {
      characters("\n");
    doIndent();
  write('<');
  writeName(uri, localName, qName, true);
  writeAttributes(atts);
  if (this.elementLevel == 1) {
    forceNSDecls();
  writeNSDecls();
  write('>');
  super.startElement(uri, localName, qName, atts);
  if (isDataFormat()) {
    this.depth++;

代码示例来源:origin: org.restlet.jee/org.restlet.ext.atom

/**
 * Writes the current object as an XML element using the given SAX writer.
 * 
 * @param writer
 *            The SAX writer.
 * @throws SAXException
 */
public void writeElement(XmlWriter writer) throws SAXException {
  writer.startElement(APP_NAMESPACE, "workspace");
  if (getTitle() != null) {
    writer.dataElement(ATOM_NAMESPACE, "title", getTitle());
  }
  for (final Collection collection : getCollections()) {
    collection.writeElement(writer);
  }
  writer.endElement(APP_NAMESPACE, "workspace");
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.wadl

/**
 * Writes the current object as an XML element using the given SAX writer.
 * 
 * @param writer
 *            The SAX writer.
 * @throws SAXException
 */
public void writeElement(XmlWriter writer) throws SAXException {
  final AttributesImpl attributes = new AttributesImpl();
  if ((getValue() != null) && !getValue().equals("")) {
    attributes.addAttribute("", "id", null, "xs:string", getValue());
  }
  if (getDocumentations().isEmpty()) {
    writer.emptyElement(APP_NAMESPACE, "option", null, attributes);
  } else {
    writer.startElement(APP_NAMESPACE, "option", null, attributes);
    for (final DocumentationInfo documentationInfo : getDocumentations()) {
      documentationInfo.writeElement(writer);
    }
    writer.endElement(APP_NAMESPACE, "option");
  }
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.atom

/**
 * Writes the representation to a XML writer.
 * 
 * @param writer
 *            The XML writer to write to.
 * @throws IOException
 */
@Override
public void write(XmlWriter writer) throws IOException {
  try {
    writer.setPrefix(ATOM_NAMESPACE, "");
    writer.setDataFormat(true);
    writer.setIndentStep(3);
    writer.startDocument();
    writeElement(writer);
    writer.endDocument();
  } catch (SAXException e) {
    IOException ioe = new IOException(
        "Unable to write the Atom feed document.");
    ioe.initCause(e);
    throw ioe;
  }
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

public void write(org.restlet.ext.xml.XmlWriter writer)
      throws IOException {
    try {
      // Start document
      writer.startDocument();
      // Append the root node
      writer.startElement("mail");
      // Append the child nodes and set their text content
      writer.startElement("status");
      writer.characters("received");
      writer.endElement("status");
      writer.startElement("subject");
      writer.characters("Message to self");
      writer.endElement("subject");
      writer.startElement("content");
      writer.characters("Doh!");
      writer.endElement("content");
      writer.startElement("accountRef");
      writer.characters(new Reference(getReference(), "..")
          .getTargetRef().toString());
      writer.endElement("accountRef");
      // End the root node
      writer.endElement("mail");
      // End the document
      writer.endDocument();
    } catch (SAXException e) {
      throw new IOException(e.getMessage());
    }
  };
};

代码示例来源:origin: org.restlet.android/org.restlet.ext.xml

public void endElement(String uri, String localName, String qName)
    throws SAXException {
  if (isDataFormat()) {
    this.depth--;
    if (this.state == SEEN_ELEMENT) {
      characters(false, "\n");
      doIndent();
  write("</");
  writeName(uri, localName, qName, true);
  write('>');
  if (this.elementLevel == 1) {
    write('\n');
  this.elementLevel--;
  if (isDataFormat()) {
    this.state = this.stateStack.pop();

代码示例来源:origin: org.restlet.jee/org.restlet.ext.wadl

writer.emptyElement(APP_NAMESPACE, "doc", null, attributes);
} else {
  writer.startElement(APP_NAMESPACE, "doc", null, attributes);
  try {
    boolean isDataFormat = writer.isDataFormat();
    writer.setDataFormat(false);
    writer.setDataFormat(isDataFormat);
  } catch (IOException e) {
    Context.getCurrentLogger()
            e);
  writer.endElement(APP_NAMESPACE, "doc");

代码示例来源:origin: org.restlet.android/org.restlet.ext.atom

/**
   * Writes the representation to a XML writer.
   * 
   * @param writer
   *            The XML writer to write to.
   * @throws SAXException
   */
  public void writeElement(XmlWriter writer) throws SAXException {
    writer.startElement(APP_NAMESPACE, "categories");

    for (final Category entry : getEntries()) {
      entry.writeElement(writer);
    }

    writer.endElement(APP_NAMESPACE, "categories");
    writer.endDocument();
  }
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.wadl

@Override
  public void write(XmlWriter writer) throws IOException {
    try {
      writer.forceNSDecl(APP_NAMESPACE, "");
      writer.setDataFormat(true);
      writer.setIndentStep(3);
      writer.processingInstruction("xml",
          "version=\"1.0\" standalone=\"yes\"");
      writer.processingInstruction("xml-stylesheet",
          "type=\"text/xsl\" href=\"wadl2html.xslt\"");
      this.application.writeElement(writer);
      writer.endDocument();
    } catch (SAXException e) {
      Context.getCurrentLogger().log(Level.SEVERE,
          "Error when writing the WADL Representation.", e);
    }
  }
}

代码示例来源:origin: org.restlet.android/org.restlet.ext.atom

/**
 * Writes the current object as an XML element using the given SAX writer.
 * 
 * @param writer
 *            The SAX writer.
 * @throws SAXException
 */
public void writeElement(XmlWriter writer) throws SAXException {
  final AttributesImpl attributes = new AttributesImpl();
  if ((getUri() != null) && (getUri().toString() != null)) {
    attributes.addAttribute("", "uri", null, "atomURI", getUri()
        .toString());
  }
  if (getVersion() != null) {
    attributes.addAttribute("", "version", null, "text", getVersion());
  }
  if (getName() != null) {
    writer.dataElement(ATOM_NAMESPACE, "generator", null, attributes,
        getName());
  } else {
    writer.emptyElement(ATOM_NAMESPACE, "generator", null, attributes);
  }
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.wadl

writer.forceNSDecl(key, getNamespaces().get(key));
writer.startElement(APP_NAMESPACE, "application");
writer.endElement(APP_NAMESPACE, "application");

代码示例来源:origin: org.restlet/org.restlet.ext.xml

/**
 * Write a string of character data, with XML escaping.
 * <p>
 * This is a convenience method that takes an XML String, converts it to a
 * character array, then invokes {@link #characters(char[], int, int)}.
 * </p>
 * 
 * @param data
 *            The character data.
 * @exception org.xml.sax.SAXException
 *                If there is an error writing the string, or if a restlet
 *                further down the filter chain raises an exception.
 * @see #characters(char[], int, int)
 */
public void characters(String data) throws SAXException {
  characters(false, data);
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.xml

if ("xmlns".equals(atts.getQName(i))) {
  forceNSDecl(atts.getValue(i));
} else if (atts.getQName(i) != null
    && atts.getQName(i).startsWith("xmlns")) {
  forceNSDecl(atts.getValue(i), atts.getLocalName(i));
} else {
  final char ch[] = atts.getValue(i).toCharArray();
  write(' ');
  writeName(atts.getURI(i), atts.getLocalName(i),
      atts.getQName(i), false);
  write("=\"");
  writeEsc(ch, 0, ch.length, true);
  write('"');

代码示例来源:origin: org.restlet/org.restlet.ext.xml

/**
 * Start a new element without a qname, attributes or a Namespace URI.
 * 
 * <p>
 * This method will provide an empty string for the Namespace URI, and empty
 * string for the qualified name, and a default empty attribute list. It
 * invokes #startElement(String, String, String, Attributes)} directly.
 * </p>
 * 
 * @param localName
 *            The element's local name.
 * @exception org.xml.sax.SAXException
 *                If there is an error writing the start tag, or if a
 *                restlet further down the filter chain raises an exception.
 * @see #startElement(String, String, String, Attributes)
 */
public void startElement(String localName) throws SAXException {
  startElement("", localName, "", this.EMPTY_ATTS);
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.xml

/**
 * End an element without a Namespace URI or qname.
 * 
 * <p>
 * This method will supply an empty string for the qName and an empty string
 * for the Namespace URI. It invokes
 * {@link #endElement(String, String, String)} directly.
 * </p>
 * 
 * @param localName
 *            The element's local name.
 * @exception org.xml.sax.SAXException
 *                If there is an error writing the end tag, or if a restlet
 *                further down the filter chain raises an exception.
 * @see #endElement(String, String, String)
 */
public void endElement(String localName) throws SAXException {
  endElement("", localName, "");
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com