Java Code Examples for org.xmlpull.v1.XmlPullParser#getAttributeNamespace()
The following examples show how to use
org.xmlpull.v1.XmlPullParser#getAttributeNamespace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLParser.java From QPM with Apache License 2.0 | 6 votes |
/** * 解析自己的attribute属性 */ private void parseAttribute(XmlPullParser parser) throws XmlPullParserException { int attributeCount = parser.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { String attributeNamespace = parser.getAttributeNamespace(i); String attributeName = parser.getAttributeName(i); String attributeValue = parser.getAttributeValue(i); if (TextUtils.isEmpty(attributeName)) { throw new XmlPullParserException("attributeName is null"); } if (TextUtils.isEmpty(attributeValue)) { continue; } if (needParseNameSpace) { String key = TextUtils.isEmpty(attributeNamespace) ? attributeName : attributeNamespace + ":" + attributeName; attributeMap.put(key, attributeValue); } else { attributeMap.put(attributeName, attributeValue); } } }
Example 2
Source File: BodyParserXmlPull.java From jbosh with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public BodyParserResults parse(final String xml) throws BOSHException { BodyParserResults result = new BodyParserResults(); Exception thrown; try { XmlPullParser xpp = getXmlPullParser(); xpp.setInput(new StringReader(xml)); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Start tag: " + xpp.getName()); } } else { eventType = xpp.next(); continue; } String prefix = xpp.getPrefix(); if (prefix == null) { prefix = XMLConstants.DEFAULT_NS_PREFIX; } String uri = xpp.getNamespace(); String localName = xpp.getName(); QName name = new QName(uri, localName, prefix); if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Start element: "); LOG.finest(" prefix: " + prefix); LOG.finest(" URI: " + uri); LOG.finest(" local: " + localName); } BodyQName bodyName = AbstractBody.getBodyQName(); if (!bodyName.equalsQName(name)) { throw(new IllegalStateException( "Root element was not '" + bodyName.getLocalPart() + "' in the '" + bodyName.getNamespaceURI() + "' namespace. (Was '" + localName + "' in '" + uri + "')")); } for (int idx=0; idx < xpp.getAttributeCount(); idx++) { String attrURI = xpp.getAttributeNamespace(idx); if (attrURI.length() == 0) { attrURI = xpp.getNamespace(null); } String attrPrefix = xpp.getAttributePrefix(idx); if (attrPrefix == null) { attrPrefix = XMLConstants.DEFAULT_NS_PREFIX; } String attrLN = xpp.getAttributeName(idx); String attrVal = xpp.getAttributeValue(idx); BodyQName aqn = BodyQName.createWithPrefix( attrURI, attrLN, attrPrefix); if (LOG.isLoggable(Level.FINEST)) { LOG.finest(" Attribute: {" + attrURI + "}" + attrLN + " = '" + attrVal + "'"); } result.addBodyAttributeValue(aqn, attrVal); } break; } return result; } catch (RuntimeException rtx) { thrown = rtx; } catch (XmlPullParserException xmlppx) { thrown = xmlppx; } catch (IOException iox) { thrown = iox; } throw(new BOSHException("Could not parse body:\n" + xml, thrown)); }
Example 3
Source File: PullReader.java From simplexml with Apache License 2.0 | 3 votes |
/** * Constructor for the <code>Entry</code> object. This creates * an attribute object that is used to extract the name, value * namespace prefix, and namespace reference from the provided * node. This is used to populate any start events created. * * @param source this is the parser used to get the attribute * @param index this is the index of the attribute to get */ public Entry(XmlPullParser source, int index) { this.reference = source.getAttributeNamespace(index); this.prefix = source.getAttributePrefix(index); this.value = source.getAttributeValue(index); this.name = source.getAttributeName(index); this.source = source; }