本文整理汇总了Java中javax.xml.stream.XMLStreamWriter.writeDefaultNamespace方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamWriter.writeDefaultNamespace方法的具体用法?Java XMLStreamWriter.writeDefaultNamespace怎么用?Java XMLStreamWriter.writeDefaultNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLStreamWriter
的用法示例。
在下文中一共展示了XMLStreamWriter.writeDefaultNamespace方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTo
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
w.writeStartElement("", name.getLocalPart(), name.getNamespaceURI());
w.writeDefaultNamespace(name.getNamespaceURI());
if (mustUnderstand) {
//Writing the ns declaration conditionally checking in the NSContext breaks XWSS. as readHeader() adds ns declaration,
// where as writing alonf with the soap envelope does n't add it.
//Looks like they expect the readHeader() and writeTo() produce the same infoset, Need to understand their usage
//if(w.getNamespaceContext().getPrefix(soapVersion.nsUri) == null) {
w.writeNamespace("S", soapVersion.nsUri);
w.writeAttribute("S", soapVersion.nsUri, MUST_UNDERSTAND, getMustUnderstandLiteral(soapVersion));
// } else {
// w.writeAttribute(soapVersion.nsUri,MUST_UNDERSTAND, getMustUnderstandLiteral(soapVersion));
// }
}
w.writeCharacters(value);
w.writeEndElement();
}
示例2: testUnboundPrefix
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Test
public void testUnboundPrefix() throws Exception {
try {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter w = xof.createXMLStreamWriter(System.out);
// here I'm trying to write
// <bar xmlns="foo" />
w.writeStartDocument();
w.writeStartElement("foo", "bar");
w.writeDefaultNamespace("foo");
w.writeCharacters("---");
w.writeEndElement();
w.writeEndDocument();
w.close();
// Unexpected success
String FAIL_MSG = "Unexpected success. Expected: " + "XMLStreamException - " + "if the namespace URI has not been bound to a prefix "
+ "and javax.xml.stream.isPrefixDefaulting has not been " + "set to true";
System.err.println(FAIL_MSG);
Assert.fail(FAIL_MSG);
} catch (XMLStreamException xmlStreamException) {
// Expected Exception
System.out.println("Expected XMLStreamException: " + xmlStreamException.toString());
}
}
示例3: writeTo
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
w.writeStartElement("", av.faultDetailTag.getLocalPart(), av.faultDetailTag.getNamespaceURI());
w.writeDefaultNamespace(av.nsUri);
w.writeStartElement("", wrapper, av.nsUri);
w.writeCharacters(problemValue);
w.writeEndElement();
w.writeEndElement();
}
示例4: writeTo
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
w.writeStartElement("", getLocalPart(), getNamespaceURI());
w.writeDefaultNamespace(getNamespaceURI());
w.writeStartElement(actionLocalName);
w.writeCharacters(action);
w.writeEndElement();
if (soapAction != null) {
w.writeStartElement(soapActionLocalName);
w.writeCharacters(soapAction);
w.writeEndElement();
}
w.writeEndElement();
}
示例5: writeTo
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Override
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
w.writeStartElement("", name.getLocalPart(), name.getNamespaceURI());
w.writeDefaultNamespace(name.getNamespaceURI());
if (type != null)
w.writeAttribute("type", type);
w.writeCharacters(value);
w.writeEndElement();
}
示例6: test1
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Test
public void test1() throws Exception {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
xof.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
StringWriter sw = new StringWriter();
XMLStreamWriter w = xof.createXMLStreamWriter(sw);
w.writeStartDocument();
w.writeStartElement("foo", "bar", "zot");
w.writeDefaultNamespace(null);
w.writeCharacters("---");
}
示例7: testRepairingPrefix
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Test
public void testRepairingPrefix() throws Exception {
try {
// repair namespaces
// use new XMLOutputFactory as changing its property settings
XMLOutputFactory xof = XMLOutputFactory.newInstance();
xof.setProperty(xof.IS_REPAIRING_NAMESPACES, new Boolean(true));
XMLStreamWriter w = xof.createXMLStreamWriter(System.out);
// here I'm trying to write
// <bar xmlns="foo" />
w.writeStartDocument();
w.writeStartElement("foo", "bar");
w.writeDefaultNamespace("foo");
w.writeCharacters("---");
w.writeEndElement();
w.writeEndDocument();
w.close();
// Expected success
System.out.println("Expected success.");
} catch (Exception exception) {
// Unexpected Exception
String FAIL_MSG = "Unexpected Exception: " + exception.toString();
System.err.println(FAIL_MSG);
Assert.fail(FAIL_MSG);
}
}
示例8: writeXcesAnnotations
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
/**
* Save annotations to the given XMLStreamWriter in XCES format. The
* writer is <i>not</i> closed by this method, that is left to the
* caller. This method writes just the cesAna element - the XML
* declaration must be filled in by the caller if required. Characters
* in feature values that are illegal in XML are replaced by
* {@link #INVALID_CHARACTER_REPLACEMENT} (a space). Feature <i>names</i>
* are not modified, nor are annotation types - an illegal character
* in one of these will cause the serialization to fail.
*
* @param annotations the annotations to save, typically an
* AnnotationSet
* @param xsw the XMLStreamWriter to write to
* @param includeId should we include the annotation IDs (as the "n"
* attribute on each <code>struct</code>)?
* @throws XMLStreamException
*/
public static void writeXcesAnnotations(Collection<Annotation> annotations,
XMLStreamWriter xsw, boolean includeId) throws XMLStreamException {
List<Annotation> annotsToDump = new ArrayList<Annotation>(annotations);
Collections.sort(annotsToDump, LONGEST_FIRST_OFFSET_COMPARATOR);
xsw.setDefaultNamespace(XCES_NAMESPACE);
xsw.writeStartElement(XCES_NAMESPACE, "cesAna");
xsw.writeDefaultNamespace(XCES_NAMESPACE);
xsw.writeAttribute("version", XCES_VERSION);
newLine(xsw);
String indent = " ";
String indentMore = indent + indent;
for(Annotation a : annotsToDump) {
long start = a.getStartNode().getOffset().longValue();
long end = a.getEndNode().getOffset().longValue();
FeatureMap fm = a.getFeatures();
xsw.writeCharacters(indent);
if(fm == null || fm.size() == 0) {
xsw.writeEmptyElement(XCES_NAMESPACE, "struct");
}
else {
xsw.writeStartElement(XCES_NAMESPACE, "struct");
}
xsw.writeAttribute("type", a.getType());
xsw.writeAttribute("from", String.valueOf(start));
xsw.writeAttribute("to", String.valueOf(end));
// include the annotation ID as the "n" attribute if requested
if(includeId) {
xsw.writeAttribute("n", String.valueOf(a.getId()));
}
newLine(xsw);
if(fm != null && fm.size() != 0) {
for(Map.Entry<Object,Object> att : fm.entrySet()) {
if(!"isEmptyAndSpan".equals(att.getKey())) {
xsw.writeCharacters(indentMore);
xsw.writeEmptyElement(XCES_NAMESPACE, "feat");
xsw.writeAttribute("name", String.valueOf(att.getKey()));
xsw.writeAttribute("value",
replaceXMLIllegalCharactersInString(String.valueOf(att
.getValue())));
newLine(xsw);
}
}
xsw.writeCharacters(indent);
xsw.writeEndElement();
newLine(xsw);
}
}
xsw.writeEndElement();
newLine(xsw);
}
示例9: writeNamespaceAttributes
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private int writeNamespaceAttributes(int item, XMLStreamWriter writer, boolean collectPrefixes, Set<String> prefixSet) throws XMLStreamException {
do {
switch(getNIIState(item)){
case STATE_NAMESPACE_ATTRIBUTE:
// Undeclaration of default namespace
writer.writeDefaultNamespace("");
if (collectPrefixes) {
prefixSet.add("");
}
break;
case STATE_NAMESPACE_ATTRIBUTE_P:
// Undeclaration of namespace
// Declaration with prefix
String prefix = readStructureString();
writer.writeNamespace(prefix, "");
if (collectPrefixes) {
prefixSet.add(prefix);
}
break;
case STATE_NAMESPACE_ATTRIBUTE_P_U:
// Declaration with prefix
prefix = readStructureString();
writer.writeNamespace(prefix, readStructureString());
if (collectPrefixes) {
prefixSet.add(prefix);
}
break;
case STATE_NAMESPACE_ATTRIBUTE_U:
// Default declaration
writer.writeDefaultNamespace(readStructureString());
if (collectPrefixes) {
prefixSet.add("");
}
break;
}
readStructure();
item = peekStructure();
} while((item & TYPE_MASK) == T_NAMESPACE_ATTRIBUTE);
return item;
}
示例10: testCR6420953
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Test
public void testCR6420953() {
try {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
StringWriter sw = new StringWriter();
XMLStreamWriter w = xof.createXMLStreamWriter(sw);
w.writeStartDocument();
w.writeStartElement("element");
w.writeDefaultNamespace(XML_CONTENT);
w.writeNamespace("prefix", XML_CONTENT);
w.writeAttribute("attribute", XML_CONTENT);
w.writeAttribute(XML_CONTENT, "attribute2", XML_CONTENT);
w.writeAttribute("prefix", XML_CONTENT, "attribute3", XML_CONTENT);
w.writeCharacters("\n");
w.writeCharacters(XML_CONTENT);
w.writeCharacters("\n");
w.writeCharacters(XML_CONTENT.toCharArray(), 0, XML_CONTENT.length());
w.writeCharacters("\n");
w.writeEndElement();
w.writeEndDocument();
w.flush();
System.out.println(sw);
// make sure that the generated XML parses
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.newDocumentBuilder().parse(new InputSource(new StringReader(sw.toString())));
} catch (XMLStreamException xmlStreamException) {
xmlStreamException.printStackTrace();
Assert.fail(xmlStreamException.toString());
} catch (SAXException saxException) {
saxException.printStackTrace();
Assert.fail(saxException.toString());
} catch (ParserConfigurationException parserConfigurationException) {
parserConfigurationException.printStackTrace();
Assert.fail(parserConfigurationException.toString());
} catch (IOException ioException) {
ioException.printStackTrace();
Assert.fail(ioException.toString());
}
}
示例11: startDocumentEmptyDefaultNamespace
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private void startDocumentEmptyDefaultNamespace(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
xmlStreamWriter.writeStartDocument();
xmlStreamWriter.writeStartElement("root");
xmlStreamWriter.writeDefaultNamespace("");
}
示例12: startDocumentSpecifiedDefaultNamespace
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private void startDocumentSpecifiedDefaultNamespace(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
xmlStreamWriter.writeStartDocument();
xmlStreamWriter.writeStartElement("root");
xmlStreamWriter.writeDefaultNamespace("http://example.org/uniqueURI");
}