本文整理汇总了Java中javax.xml.stream.XMLStreamReader.getNamespaceCount方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader.getNamespaceCount方法的具体用法?Java XMLStreamReader.getNamespaceCount怎么用?Java XMLStreamReader.getNamespaceCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLStreamReader
的用法示例。
在下文中一共展示了XMLStreamReader.getNamespaceCount方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNamespaceCount
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testNamespaceCount() {
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(rootElement)) {
int count = sr.getNamespaceCount();
Assert.assertTrue(count == 1);
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例2: testNamespaceCount
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test
public void testNamespaceCount() {
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(rootElement)) {
int count = sr.getNamespaceCount();
Assert.assertTrue(count == 3);
}
}
}
} catch (Exception ex) {
Assert.fail("Exception: " + ex.getMessage());
}
}
示例3: storeElementWithInScopeNamespaces
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
private void storeElementWithInScopeNamespaces(XMLStreamReader reader) {
storeQualifiedName(T_ELEMENT_LN,
reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName());
if (reader.getNamespaceCount() > 0) {
storeNamespaceAttributes(reader);
}
if (reader.getAttributeCount() > 0) {
storeAttributes(reader);
}
}
示例4: storeElement
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
private void storeElement(XMLStreamReader reader) {
storeQualifiedName(T_ELEMENT_LN,
reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName());
if (reader.getNamespaceCount() > 0) {
storeNamespaceAttributes(reader);
}
if (reader.getAttributeCount() > 0) {
storeAttributes(reader);
}
}
示例5: addNamespaces
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
protected void addNamespaces(StartElementEvent event,XMLStreamReader streamReader){
Namespace namespace = null;
for(int i=0; i<streamReader.getNamespaceCount(); i++){
namespace = factory.createNamespace(streamReader.getNamespacePrefix(i),
streamReader.getNamespaceURI(i));
event.addNamespace(namespace);
}
}
示例6: AttributesImpl
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public AttributesImpl(XMLStreamReader reader) {
if (reader == null) {
// this is the case when we call getAttributes() on the
// reader when it is not on a start tag
atInfos = new AttributeInfo[0];
} else {
// this is the normal case
int index = 0;
int namespaceCount = reader.getNamespaceCount();
int attributeCount = reader.getAttributeCount();
atInfos = new AttributeInfo[namespaceCount + attributeCount];
for (int i=0; i<namespaceCount; i++) {
String namespacePrefix = reader.getNamespacePrefix(i);
// will be null if default prefix. QName can't take null
if (namespacePrefix == null) {
namespacePrefix = "";
}
atInfos[index++] = new AttributeInfo(
new QName(XMLNS_NAMESPACE_URI,
namespacePrefix,
"xmlns"),
reader.getNamespaceURI(i));
}
for (int i=0; i<attributeCount; i++) {
atInfos[index++] = new AttributeInfo(
reader.getAttributeName(i),
reader.getAttributeValue(i));
}
}
}
示例7: fillDeclaredPrefixes
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/** Fills in the list of declared prefixes. */
private void fillDeclaredPrefixes(XMLStreamReader reader) {
fDeclaredPrefixes.clear();
final int len = reader.getNamespaceCount();
for (int i = 0; i < len; ++i) {
String prefix = reader.getNamespacePrefix(i);
fDeclaredPrefixes.add(prefix != null ? prefix : "");
}
}
示例8: storeNamespaceAttributes
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
private void storeNamespaceAttributes(XMLStreamReader reader) {
int count = reader.getNamespaceCount();
for (int i = 0; i < count; i++) {
storeNamespaceAttribute(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
}
示例9: printNamespaces
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
protected static void printNamespaces(XMLStreamReader xmlr) {
for (int i = 0; i < xmlr.getNamespaceCount(); i++) {
printNamespace(xmlr, i);
}
}