本文整理汇总了Java中javax.xml.namespace.NamespaceContext.getPrefixes方法的典型用法代码示例。如果您正苦于以下问题:Java NamespaceContext.getPrefixes方法的具体用法?Java NamespaceContext.getPrefixes怎么用?Java NamespaceContext.getPrefixes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.namespace.NamespaceContext
的用法示例。
在下文中一共展示了NamespaceContext.getPrefixes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toXpathContext
import javax.xml.namespace.NamespaceContext; //导入方法依赖的package包/类
private XPathContext toXpathContext(NamespaceContext namespaceContext) {
XPathContext context = new XPathContext();
Iterator prefixes = namespaceContext.getPrefixes("http://www.example.com/my");
while (prefixes.hasNext()) {
String prefix = (String) prefixes.next();
context.addNamespace(prefix, namespaceContext.getNamespaceURI(prefix));
}
return context;
}
示例2: isPrefixDeclared
import javax.xml.namespace.NamespaceContext; //导入方法依赖的package包/类
private static boolean isPrefixDeclared(XMLStreamWriter writer, String nsUri, String prefix) {
boolean prefixDecl = false;
NamespaceContext nscontext = writer.getNamespaceContext();
Iterator prefixItr = nscontext.getPrefixes(nsUri);
while (prefixItr.hasNext()) {
if (prefix.equals(prefixItr.next())) {
prefixDecl = true;
break;
}
}
return prefixDecl;
}
示例3: testTwo
import javax.xml.namespace.NamespaceContext; //导入方法依赖的package包/类
@Test
public void testTwo() {
System.out.println("Test StreamWriter's Namespace Context");
try {
String outputFile = USER_DIR + files[1] + ".out";
System.out.println("Writing output to " + outputFile);
xtw = outputFactory.createXMLStreamWriter(System.out);
xtw.writeStartDocument();
xtw.writeStartElement("elemTwo");
xtw.setPrefix("html", "http://www.w3.org/TR/REC-html40");
xtw.writeNamespace("html", "http://www.w3.org/TR/REC-html40");
xtw.writeEndDocument();
NamespaceContext nc = xtw.getNamespaceContext();
// Got a Namespace Context.class
XMLStreamWriter xtw1 = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING);
xtw1.writeComment("all elements here are explicitly in the HTML namespace");
xtw1.setNamespaceContext(nc);
xtw1.writeStartDocument("utf-8", "1.0");
xtw1.setPrefix("htmlOne", "http://www.w3.org/TR/REC-html40");
NamespaceContext nc1 = xtw1.getNamespaceContext();
xtw1.close();
Iterator it = nc1.getPrefixes("http://www.w3.org/TR/REC-html40");
// FileWriter fw = new FileWriter(outputFile);
while (it.hasNext()) {
System.out.println("Prefixes :" + it.next());
// fw.write((String)it.next());
// fw.write(";");
}
// fw.close();
// assertTrue(checkResults(testTwo+".out", testTwo+".org"));
System.out.println("Done");
} catch (Exception ex) {
Assert.fail("testTwo Failed " + ex);
ex.printStackTrace();
}
}