本文整理汇总了Java中javax.xml.stream.events.StartElement.getAttributeByName方法的典型用法代码示例。如果您正苦于以下问题:Java StartElement.getAttributeByName方法的具体用法?Java StartElement.getAttributeByName怎么用?Java StartElement.getAttributeByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.events.StartElement
的用法示例。
在下文中一共展示了StartElement.getAttributeByName方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAttributeByName
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private Attribute getAttributeByName(final StartElement element,
final QName attributeName) {
// call standard API method to retrieve the attribute by name
Attribute attribute = element.getAttributeByName(attributeName);
// try to find the attribute without a prefix.
if (attribute == null) {
final String localAttributeName = attributeName.getLocalPart();
final Iterator iterator = element.getAttributes();
while (iterator.hasNext()) {
final Attribute nextAttribute = (Attribute) iterator.next();
final QName aName = nextAttribute.getName();
final boolean attributeFoundByWorkaround = aName.equals(attributeName) || (aName.getLocalPart().equals(localAttributeName) && (aName.getPrefix() == null || "".equals(aName.getPrefix())));
if (attributeFoundByWorkaround) {
attribute = nextAttribute;
break;
}
}
}
return attribute;
}
示例2: getImageCoverage
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private String getImageCoverage(XMLEventReader reader) throws XMLStreamException {
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
StartElement element = event.asStartElement();
String localPart = element.getName().getLocalPart();
if ("image".equals(localPart)) {
QName hrefQName = new QName("http://www.w3.org/1999/xlink", "href");
Attribute href = element.getAttributeByName(hrefQName);
return href.getValue();
}
}
if (event.isEndElement() && "coverage".equals(event.asEndElement().getName().getLocalPart())) {
return null;
}
}
return null;
}
示例3: nonSvgAttributesRemoved
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
public static Predicate<XmlEventProcessorTester> nonSvgAttributesRemoved() {
return tester -> {
StartElement element = tester.getProcessedResult(0).asStartElement();
QName name = new QName("http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd", "name", "sodipodi");
return element.getAttributeByName(name) == null;
};
}
示例4: svgAttributesRemain
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
public static Predicate<XmlEventProcessorTester> svgAttributesRemain() {
return tester -> {
StartElement element = tester.getProcessedResult(0).asStartElement();
Attribute path = element.getAttributeByName(new QName(SvgDocument.NAMESPACE_URI, "path"));
Attribute rect = element.getAttributeByName(new QName(SvgDocument.NAMESPACE_URI, "rect"));
return path != null && rect != null;
};
}
示例5: parseTitleInfo
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private void parseTitleInfo(XMLEventReader reader, BookInfo bookInfo) throws XMLStreamException {
Book book = bookInfo.getBook();
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (event.isEndElement() && "title-info".equals(event.asEndElement().getName().getLocalPart())) {
break;
} else if (event.isStartElement()) {
StartElement element = event.asStartElement();
String localPart = element.getName().getLocalPart();
if ("author".equals(localPart)) {
Author author = parseAuthor(reader);
book.addAuthor(author);
} else if ("coverpage".equals(localPart)) {
bookInfo.setCoverage(getImageCoverage(reader));
} else if ("book-title".equals(localPart)) {
book.setTitle(reader.getElementText());
} else if ("annotation".equals(localPart)) {
book.setDescr(getText(reader, "annotation"));
} else if ("genre".equals(localPart)) {
book.getGenres().add(new BookGenre(book, new Genre(reader.getElementText())));
} else if ("sequence".equals(localPart)) {
String sequenceName = element.getAttributeByName(new QName("", "name")).getValue();
Integer order;
try {
Attribute numberAttr = element.getAttributeByName(new QName("", "number"));
order = numberAttr == null ? 0 : Integer.valueOf(numberAttr.getValue());
} catch (NumberFormatException e) {
order = 0;
log.warn("sequence {} without order, book: {}", sequenceName, book.getTitle());
}
book.getSequences().add(new BookSequence(order, new Sequence(sequenceName)));
}
}
}
}
示例6: parseVersionFromElement
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private SchemaVersion parseVersionFromElement(StartElement element) {
Attribute schemaVersion = element.getAttributeByName(SCHEMA_VERSION_QNAME);
if (schemaVersion != null) {
return new SchemaVersion(schemaVersion.getValue());
} else {
throw new OpenGammaRuntimeException("No schema version was found - unable to parse file");
}
}
示例7: parseTemplate
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
/**
* Parses a template. This function is to be called upon encountering a {@code template} StartElement.
*
* @param r The XMLEventReader to use.
* @param parent The parent WikiText the resulting WTemplate is to belong to, if applicable. Set null to disable.
* @return The parsed WTemplate.
* @throws Throwable On parse error.
*/
private static WTemplate parseTemplate(XMLEventReader r, WikiText parent) throws Throwable
{
WTemplate t = new WTemplate(parent);
String lastNameParsed = "";
while (r.hasNext())
{
XMLEvent e = r.nextEvent();
if (e.isStartElement())
{
StartElement se = e.asStartElement();
switch (se.getName().getLocalPart())
{
case "title":
t.title = getNextElementText(r).trim();
break;
case "name":
Attribute index = se.getAttributeByName(new QName("index"));
lastNameParsed = index != null ? index.getValue() : getNextElementText(r).trim();
break;
case "equals":
getNextElementText(r);
break;
case "value":
t.put(lastNameParsed, parseTValue(r));
break;
default:
// do nothing - skip part tags
}
}
else if (e.isEndElement() && nameIs(e.asEndElement(), "template"))
break;
}
return t;
}
示例8: parse
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
public void parse() throws Exception {
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
InputStream is = IOUtils.getInputStream(getInputFileName());
XMLEventReader xmlEventReader = xmlInputFactory
.createXMLEventReader(is);
boolean isDoc = false;
boolean isFacet = false;
boolean isArr = false;
int lstCounter = 0;
String currentValue = "";
String currentName = "";
List<String> possibleStartElements = Arrays.asList("date,arr,str,bool,double,float,long,int".split(","));
while (xmlEventReader.hasNext()) {
XMLEvent xmlEvent = xmlEventReader.nextEvent();
if (xmlEvent.isStartElement()) {
StartElement startElement = xmlEvent.asStartElement();
if (startElement.getAttributeByName(new QName("name")) != null) {
currentName = startElement.getAttributeByName(
new QName("name")).getValue();
}
if (startElement.getName().getLocalPart().equals("doc")) {
isDoc = true;
}
if (startElement.getName().getLocalPart().equals("lst")) {
lstCounter ++;
if(isFacet)
if("facet_fields".equals(currentName)) {
isFacet = true;
}
}
} else if (xmlEvent.isEndElement()) {
EndElement endElement = xmlEvent.asEndElement();
if (endElement.getName().getLocalPart().equals("doc")) {
isDoc = false;
endDocument();
} else if (endElement.getName().getLocalPart().equals("arr")) {
currentName = "";
} else if (isDoc && possibleStartElements.contains(endElement.getName().getLocalPart())) {
if (currentName != null && !"".equals(currentName)) {
field(currentName, currentValue);
}
currentValue = "";
} else if (endElement.getName().getLocalPart().equals("lst")) {
lstCounter--;
} else {
}
} else if (xmlEvent.isCharacters()) {
Characters characters = xmlEvent.asCharacters();
currentValue = characters.getData();
}
}
is.close();
xmlEventReader.close();
}
示例9: getAttributeValue
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private static String getAttributeValue(StartElement ele, String attrName) {
Attribute attr = ele.getAttributeByName(new QName(attrName));
return attr != null ? attr.getValue() : null;
}
示例10: currency
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
private void currency(XMLEventReader xml) throws XMLStreamException {
IsoCurrencyInformation isoCurrencyInformation = new IsoCurrencyInformation();
while (true) {
XMLEvent event = xml.nextEvent();
if (event.isStartElement()) {
StartElement startElement = event.asStartElement();
String startName = startElement.getName().getLocalPart();
switch (startName) {
case _CTRY_NM:
isoCurrencyInformation.ctryNm = token(xml);
break;
case _CCY_NM:
Attribute isFundAttribute = startElement.getAttributeByName(new QName("IsFund"));
if (isFundAttribute != null && "true".equals(isFundAttribute.getValue())) {
isoCurrencyInformation.fund = true;
}
isoCurrencyInformation.ccyNm = token(xml);
break;
case _CCY:
isoCurrencyInformation.ccy = token(xml);
break;
case _CCY_NBR:
isoCurrencyInformation.ccyNbr = Integer.valueOf(token(xml));
break;
case _CCY_MNR_UNTS:
String value = token(xml);
if (StringUtils.equals("N.A.", value)) {
isoCurrencyInformation.ccyMnrUnts = null;
} else {
isoCurrencyInformation.ccyMnrUnts = Integer.valueOf(value);
}
break;
default:
skip(xml);
}
} else if (event.isEndElement()) {
isoCurrencyInformations.add(isoCurrencyInformation);
break;
}
}
}
示例11: parseXML
import javax.xml.stream.events.StartElement; //导入方法依赖的package包/类
@Override
protected List<DataCell[]> parseXML(InputStream in)
throws ExecuteException, IOException, SAXException,
XMLStreamException
{
List<DataCell[]> list=new ArrayList<DataCell[]>();
DataCell[] curr=null;
int depth=0;
Attribute att;
XMLEventReader reader=super.xmlInputFactory.createXMLEventReader(new StreamSource(in));
while(reader.hasNext())
{
XMLEvent evt=reader.nextEvent();
if(evt.isEndElement())
{
--depth;
continue;
}
if(!evt.isStartElement()) continue;
++depth;
StartElement s=evt.asStartElement();
String localName=s.getName().getLocalPart();
if(localName.equals("Rs") && depth==2)
{
att=s.getAttributeByName(new QName("rsId"));
curr=new DataCell[]{
new IntCell(Integer.parseInt(att.getValue())),
DataType.getMissingCell(),
DataType.getMissingCell()
};
list.add(curr);
}
else if(localName.equals("Het") && curr[1].isMissing() && depth==3)
{
att=s.getAttributeByName(new QName("value"));
if(att!=null)
{
curr[1]=new DoubleCell(Double.parseDouble(att.getValue()));
}
}
else if(localName.equals("Observed") && curr[2].isMissing() && depth==4 )
{
curr[2]=new StringCell(reader.getElementText());
--depth;
}
}
return list;
}