本文整理匯總了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());
}
}