本文整理汇总了Java中javax.xml.stream.XMLStreamReader.getNamespaceContext方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader.getNamespaceContext方法的具体用法?Java XMLStreamReader.getNamespaceContext怎么用?Java XMLStreamReader.getNamespaceContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLStreamReader
的用法示例。
在下文中一共展示了XMLStreamReader.getNamespaceContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNamespaceContext
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testNamespaceContext() {
try {
XMLInputFactory xif = XMLInputFactory.newInstance();
xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
InputStream is = new java.io.ByteArrayInputStream(getXML().getBytes());
XMLStreamReader sr = xif.createXMLStreamReader(is);
NamespaceContext context = sr.getNamespaceContext();
Assert.assertTrue(context.getPrefix("") == null);
} catch (IllegalArgumentException iae) {
Assert.fail("NamespacePrefix#getPrefix() should not throw an IllegalArgumentException for empty uri. ");
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例2: testNamespaceContext
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testNamespaceContext() {
try {
XMLInputFactory xif = XMLInputFactory.newInstance();
xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
InputStream is = new java.io.ByteArrayInputStream(getXML().getBytes());
XMLStreamReader sr = xif.createXMLStreamReader(is);
while (sr.hasNext()) {
int eventType = sr.next();
if (eventType == XMLStreamConstants.START_ELEMENT) {
if (sr.getLocalName().equals(childElement)) {
NamespaceContext context = sr.getNamespaceContext();
Assert.assertTrue(context.getPrefix(namespaceURI).equals(prefix));
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例3: testNamespaceContext
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testNamespaceContext() {
is = new java.io.ByteArrayInputStream(getXML().getBytes());
try {
XMLStreamReader sr = factory.createFilteredReader(factory.createXMLStreamReader(is), (StreamFilter) filter);
while (sr.hasNext()) {
int eventType = sr.next();
if (eventType == XMLStreamConstants.START_ELEMENT) {
if (sr.getLocalName().equals(childElement)) {
NamespaceContext context = sr.getNamespaceContext();
Assert.assertTrue(context.getPrefix(namespaceURIApple).equals(prefixApple));
}
}
}
} catch (Exception ex) {
Assert.fail("Exception: " + ex.getMessage());
}
}