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