Java Code Examples for javax.xml.stream.XMLEventReader#nextEvent()

The following examples show how to use javax.xml.stream.XMLEventReader#nextEvent() . 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: ParseWikipedia.java    From WikipediaEntities with GNU Affero General Public License v3.0 6 votes vote down vote up
private String parseTextContents(XMLEventReader eventReader) throws XMLStreamException {
  // Chances are that we'll only need one string.
  String ret = null;
  buf.setLength(0);
  while(eventReader.hasNext()) {
    XMLEvent event = eventReader.nextEvent();
    if(event.isEndElement())
      break;
    if(event.isCharacters()) {
      if(ret == null)
        ret = event.asCharacters().getData();
      else { // Need to use the buffer
        if(buf.length() == 0)
          buf.append(ret);
        buf.append(event.asCharacters().getData());
      }
    }
  }
  if(buf.length() > 0) {
    ret = buf.toString();
  }
  return ret;
}
 
Example 2
Source File: UploadActionListener.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
public static Boolean reportIsEmpty(File reportFile) throws IOException, XMLStreamException {
	BufferedReader br = Files.newBufferedReader(reportFile.toPath());
	try {
		XMLEventReader reader = xmlInputFactory.createXMLEventReader(br);

		while(reader.hasNext()) {
			XMLEvent event = reader.nextEvent();
			if(event.isStartElement() && !event.asStartElement().getName().getLocalPart().equals("OWASPZAPReport")) {
				return false;
			}
		}
	} finally {
		br.close();
	}
	return true;
}
 
Example 3
Source File: RestXMLResponseParser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private List<MessagePart> parseChildrenMessages(XMLEventReader reader) throws XMLStreamException {
    ArrayList<MessagePart> messages = new ArrayList<>();
    int level = 0;
    while (reader.hasNext() && (level > -1)) {
        XMLEvent event = reader.nextEvent();
        if (event.isStartElement()) {
            if (level++ == 1) {
                StartElement element = event.asStartElement();
                String elementName = element.getName().getLocalPart();
                if (MAP.equals(elementName)) {
                    messages.add(parseChildMessage(reader));
                    level--;
                }
            }
        } else {
            level--;
        }

    }
    return messages;
}
 
Example 4
Source File: AtomDeserializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void common(final XMLEventReader reader, final StartElement start,
    final AbstractODataObject object, final String key) throws XMLStreamException {

  boolean foundEndElement = false;
  while (reader.hasNext() && !foundEndElement) {
    final XMLEvent event = reader.nextEvent();

    if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
      object.setCommonProperty(key, event.asCharacters().getData());
    }

    if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
      foundEndElement = true;
    }
  }
}
 
Example 5
Source File: ODataXmlDeserializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void collection(final Valuable valuable, final XMLEventReader reader, final StartElement start,
    final EdmType edmType, final boolean isNullable, final Integer maxLength, final Integer precision,
    final Integer scale, final boolean isUnicode) throws XMLStreamException, EdmPrimitiveTypeException,
    DeserializerException {

  List<Object> values = new ArrayList<Object>();
  boolean foundEndProperty = false;
  while (reader.hasNext() && !foundEndProperty) {
    final XMLEvent event = reader.nextEvent();
    if (event.isStartElement()) {
      if (edmType instanceof EdmPrimitiveType) {
        values.add(primitive(reader, event.asStartElement(), edmType, isNullable,
            maxLength, precision, scale, isUnicode));
      } else if (edmType instanceof EdmComplexType) {
        values.add(complex(reader, event.asStartElement(), (EdmComplexType) edmType));
      }
      // do not add null or empty values
    }

    if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
      foundEndProperty = true;
    }
  }
  valuable.setValue(getValueType(edmType, true), values);
}
 
Example 6
Source File: AtomGeoValueDeserializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private MultiPolygon multiPolygon(final XMLEventReader reader, final StartElement start,
    final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException {

  final List<Polygon> polygons = new ArrayList<>();

  boolean foundEndProperty = false;
  while (reader.hasNext() && !foundEndProperty) {
    final XMLEvent event = reader.nextEvent();

    if (event.isStartElement() && event.asStartElement().getName().equals(Constants.QNAME_POLYGON)) {
      polygons.add(polygon(reader, event.asStartElement(), type, null));
    }

    if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) {
      foundEndProperty = true;
    }
  }

  return new MultiPolygon(GeoUtils.getDimension(type), srid, polygons);
}
 
Example 7
Source File: AtomDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private PropertyType guessPropertyType(final XMLEventReader reader, final EdmTypeInfo typeInfo)
    throws XMLStreamException {

  XMLEvent child = null;
  while (reader.hasNext() && child == null) {
    final XMLEvent event = reader.peek();
    if (event.isCharacters() && event.asCharacters().isWhiteSpace()) {
      reader.nextEvent();
    } else {
      child = event;
    }
  }

  final PropertyType type;
  if (child == null) {
    type = typeInfo == null || typeInfo.isPrimitiveType() ? PropertyType.PRIMITIVE : PropertyType.ENUM;
  } else {
    if (child.isStartElement()) {
      if (Constants.NS_GML.equals(child.asStartElement().getName().getNamespaceURI())) {
        type = PropertyType.PRIMITIVE;
      } else if (elementQName.equals(child.asStartElement().getName())) {
        type = PropertyType.COLLECTION;
      } else {
        type = PropertyType.COMPLEX;
      }
    } else if (child.isCharacters()) {
      type = typeInfo == null || typeInfo.isPrimitiveType()
          ? PropertyType.PRIMITIVE
              : PropertyType.ENUM;
    } else {
      type = PropertyType.EMPTY;
    }
  }

  return type;
}
 
Example 8
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private String unmarshalNodeContent(final NamespaceVersion nsVersion, final ModelNode node, final QName nodeElementName, final XMLEventReader reader) throws PolicyException {
    StringBuilder valueBuffer = null;

    loop:
    while (reader.hasNext()) {
        try {
            final XMLEvent xmlParserEvent = reader.nextEvent();
            switch (xmlParserEvent.getEventType()) {
                case XMLStreamConstants.COMMENT:
                    break; // skipping the comments
                case XMLStreamConstants.CHARACTERS:
                    valueBuffer = processCharacters(node.getType(), xmlParserEvent.asCharacters(), valueBuffer);
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    checkEndTagName(nodeElementName, xmlParserEvent.asEndElement());
                    break loop; // data exctraction for currently processed policy node is done
                case XMLStreamConstants.START_ELEMENT:
                    final StartElement childElement = xmlParserEvent.asStartElement();

                    ModelNode childNode = addNewChildNode(nsVersion, node, childElement);
                    String value = unmarshalNodeContent(nsVersion, childNode, childElement.getName(), reader);

                    if (childNode.isDomainSpecific()) {
                        parseAssertionData(nsVersion, value, childNode, childElement);
                    }
                    break;
                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0011_UNABLE_TO_UNMARSHALL_POLICY_XML_ELEM_EXPECTED()));
            }
        } catch (XMLStreamException e) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e));
        }
    }

    return (valueBuffer == null) ? null : valueBuffer.toString().trim();
}
 
Example 9
Source File: Parser.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
private String getCharacterData(XMLEvent event, XMLEventReader eventReader)
		throws XMLStreamException {
	String result = "";
	event = eventReader.nextEvent();
	if (event instanceof Characters) {
		result = event.asCharacters().getData();
	}
	return result;
}
 
Example 10
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private Map<URI, Policy> unmarshal(final XMLEventReader reader, final StartElement parentElement) throws PolicyException {
    XMLEvent event = null;
    while (reader.hasNext()) {
        try {
            event = reader.peek();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.COMMENT:
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.CHARACTERS:
                    processCharacters(event.asCharacters(), parentElement, map);
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.END_ELEMENT:
                    processEndTag(event.asEndElement(), parentElement);
                    reader.nextEvent();
                    return map;

                case XMLStreamConstants.START_ELEMENT:
                    final StartElement element = event.asStartElement();
                    processStartTag(element, parentElement, reader, map);
                    break;

                case XMLStreamConstants.END_DOCUMENT:
                    return map;

                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0087_UNKNOWN_EVENT(event)));
            }
        } catch (XMLStreamException e) {
            final Location location = event == null ? null : event.getLocation();
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(location)), e);
        }
    }
    return map;
}
 
Example 11
Source File: ExternalAttachmentsUnmarshaller.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Map<URI, Policy> unmarshal(final XMLEventReader reader, final StartElement parentElement) throws PolicyException {
    XMLEvent event = null;
    while (reader.hasNext()) {
        try {
            event = reader.peek();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.COMMENT:
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.CHARACTERS:
                    processCharacters(event.asCharacters(), parentElement, map);
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.END_ELEMENT:
                    processEndTag(event.asEndElement(), parentElement);
                    reader.nextEvent();
                    return map;

                case XMLStreamConstants.START_ELEMENT:
                    final StartElement element = event.asStartElement();
                    processStartTag(element, parentElement, reader, map);
                    break;

                case XMLStreamConstants.END_DOCUMENT:
                    return map;

                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0087_UNKNOWN_EVENT(event)));
            }
        } catch (XMLStreamException e) {
            final Location location = event == null ? null : event.getLocation();
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(location)), e);
        }
    }
    return map;
}
 
Example 12
Source File: XmlResourceValues.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Nullable
static StartElement findNextStart(XMLEventReader eventReader) throws XMLStreamException {
  while (eventReader.hasNext()) {
    XMLEvent event = eventReader.nextEvent();
    if (event.isStartElement()) {
      return event.asStartElement();
    }
  }
  return null;
}
 
Example 13
Source File: SkipDTDTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void runReader(XMLInputFactory factory, int offset) throws XMLStreamException {
    StringReader stringReader = new StringReader(createXMLDocument(offset));
    XMLEventReader reader = factory.createXMLEventReader(stringReader);

    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        System.out.println("Event Type: " + event.getEventType());
    }
}
 
Example 14
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void processStartTag(final StartElement element, final StartElement parent,
        final XMLEventReader reader, final Map<URI, Policy> map)
        throws PolicyException {
    try {
        final QName name = element.getName();
        if (parent == null) {
            if (!name.equals(POLICIES)) {
                throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<Policies>", name, element.getLocation())));
            }
        } else {
            final QName parentName = parent.getName();
            if (parentName.equals(POLICIES)) {
                if (!name.equals(POLICY_ATTACHMENT)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<PolicyAttachment>", name, element.getLocation())));
                }
            } else if (parentName.equals(POLICY_ATTACHMENT)) {
                if (name.equals(POLICY)) {
                    readPolicy(reader);
                    return;
                } else if (!name.equals(APPLIES_TO)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<AppliesTo> or <Policy>", name, element.getLocation())));
                }
            } else if (parentName.equals(APPLIES_TO)) {
                if (!name.equals(URI)) {
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0089_EXPECTED_ELEMENT("<URI>", name, element.getLocation())));
                }
            } else {
                throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0090_UNEXPECTED_ELEMENT(name, element.getLocation())));
            }
        }
        reader.nextEvent();
        this.unmarshal(reader, element);
    } catch (XMLStreamException e) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(element.getLocation()), e));
    }
}
 
Example 15
Source File: SkipDTDTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runReader(XMLInputFactory factory, int offset) throws XMLStreamException {
    StringReader stringReader = new StringReader(createXMLDocument(offset));
    XMLEventReader reader = factory.createXMLEventReader(stringReader);

    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        System.out.println("Event Type: " + event.getEventType());
    }
}
 
Example 16
Source File: StAXSchemaParser.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void parse(XMLEventReader input) throws XMLStreamException, XNIException {
    XMLEvent currentEvent = input.peek();
    if (currentEvent != null) {
        int eventType = currentEvent.getEventType();
        if (eventType != XMLStreamConstants.START_DOCUMENT &&
            eventType != XMLStreamConstants.START_ELEMENT) {
            throw new XMLStreamException();
        }
        fLocationWrapper.setLocation(currentEvent.getLocation());
        fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
        loop: while (input.hasNext()) {
            currentEvent = input.nextEvent();
            eventType = currentEvent.getEventType();
            switch (eventType) {
            case XMLStreamConstants.START_ELEMENT:
                ++fDepth;
                StartElement start = currentEvent.asStartElement();
                fillQName(fElementQName, start.getName());
                fLocationWrapper.setLocation(start.getLocation());
                fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
                fillXMLAttributes(start);
                fillDeclaredPrefixes(start);
                addNamespaceDeclarations();
                fNamespaceContext.pushContext();
                fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
                break;
            case XMLStreamConstants.END_ELEMENT:
                EndElement end = currentEvent.asEndElement();
                fillQName(fElementQName, end.getName());
                fillDeclaredPrefixes(end);
                fLocationWrapper.setLocation(end.getLocation());
                fSchemaDOMParser.endElement(fElementQName, null);
                fNamespaceContext.popContext();
                --fDepth;
                if (fDepth <= 0) {
                    break loop;
                }
                break;
            case XMLStreamConstants.CHARACTERS:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                break;
            case XMLStreamConstants.SPACE:
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true);
                break;
            case XMLStreamConstants.CDATA:
                fSchemaDOMParser.startCDATA(null);
                sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
                fSchemaDOMParser.endCDATA(null);
                break;
            case XMLStreamConstants.PROCESSING_INSTRUCTION:
                ProcessingInstruction pi = (ProcessingInstruction)currentEvent;
                fillProcessingInstruction(pi.getData());
                fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null);
                break;
            case XMLStreamConstants.DTD:
                /* There shouldn't be a DTD in the schema */
                break;
            case XMLStreamConstants.ENTITY_REFERENCE:
                /* Not needed for schemas */
                break;
            case XMLStreamConstants.COMMENT:
                /* No point in sending comments */
                break;
            case XMLStreamConstants.START_DOCUMENT:
                fDepth++;
                /* We automatically call startDocument before the loop */
                break;
            case XMLStreamConstants.END_DOCUMENT:
                /* We automatically call endDocument after the loop */
                break;
            }
        }
        fLocationWrapper.setLocation(null);
        fNamespaceContext.setNamespaceContext(null);
        fSchemaDOMParser.endDocument(null);
    }
}
 
Example 17
Source File: XMLUtilities.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
@Override
public InputStream selectEntity(final InputStream entity, final String[] propertyNames) throws Exception {
  final XMLEventReader reader = getEventReader(entity);

  final ByteArrayOutputStream bos = new ByteArrayOutputStream();
  final XMLEventWriter writer = getEventWriter(bos);

  final List<String> found = new ArrayList<String>(Arrays.asList(propertyNames));

  boolean inProperties = false;
  boolean writeCurrent = true;
  Boolean writeNext = null;
  String currentName = null;

  final List<String> fieldToBeSaved = new ArrayList<String>(Arrays.asList(propertyNames));

  while (reader.hasNext()) {
    final XMLEvent event = reader.nextEvent();
    if (event.getEventType() == XMLStreamConstants.START_ELEMENT
        && Constants.get(ConstantKey.LINK).equals(event.asStartElement().getName().getLocalPart())
        && !fieldToBeSaved.contains(
            event.asStartElement().getAttributeByName(new QName("title")).getValue())
        && !"edit".equals(event.asStartElement().getAttributeByName(new QName("rel")).getValue())) {
      writeCurrent = false;
    } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT
        && Constants.get(ConstantKey.LINK).equals(event.asEndElement().getName().getLocalPart())) {
      writeNext = true;
    } else if (event.getEventType() == XMLStreamConstants.START_ELEMENT
        && (Constants.get(ConstantKey.PROPERTIES)).equals(
            event.asStartElement().getName().getLocalPart())) {
      writeCurrent = true;
      writeNext = false;
      inProperties = true;
    } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT
        && (Constants.get(ConstantKey.PROPERTIES)).equals(
            event.asEndElement().getName().getLocalPart())) {
      writeCurrent = true;
    } else if (inProperties) {
      if (event.getEventType() == XMLStreamConstants.START_ELEMENT) {
        final String elementName = event.asStartElement().getName().getLocalPart();

        for (String propertyName : propertyNames) {
          if ((Constants.get(ConstantKey.ATOM_PROPERTY_PREFIX) + propertyName.trim()).equals(elementName)) {
            writeCurrent = true;
            found.remove(propertyName);
            currentName = propertyName;
          }
        }

      } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT
          && StringUtils.isNotBlank(currentName)
          && (Constants.get(ConstantKey.ATOM_PROPERTY_PREFIX) + currentName.trim()).equals(
              event.asEndElement().getName().getLocalPart())) {
        writeNext = false;
        currentName = null;
      }

    }

    if (writeCurrent) {
      writer.add(event);
    }

    if (writeNext != null) {
      writeCurrent = writeNext;
      writeNext = null;
    }
  }

  writer.flush();
  writer.close();
  reader.close();
  IOUtils.closeQuietly(entity);

  // Do not raise any exception in order to support FC properties as well
  // if (!found.isEmpty()) {
  // throw new Exception(String.format("Could not find a properties '%s'", found));
  // }
  return new ByteArrayInputStream(bos.toByteArray());
}
 
Example 18
Source File: SearchHandle.java    From java-client-api with Apache License 2.0 4 votes vote down vote up
private void collectResult(XMLEventReader reader, StartElement element)
  throws XMLStreamException
{
  QName snippetName       = new QName(SEARCH_NS, "snippet");
  QName extractedName     = new QName(SEARCH_NS, "extracted");
  QName extractedNoneName = new QName(SEARCH_NS, "extracted-none");
  QName metadataName      = new QName(SEARCH_NS, "metadata");
  QName similarName       = new QName(SEARCH_NS, "similar");
  QName relevanceInfoName = new QName(QUERY_NS,  "relevance-info");

  List<XMLEvent> eventBuf = new ArrayList<>();

  QName resultName = element.getName();
  events: while (reader.hasNext()) {
    XMLEvent event = reader.nextEvent();

    int eventType = event.getEventType();
    eventType: switch (eventType) {
      case XMLStreamConstants.START_ELEMENT:
        StartElement startElement = event.asStartElement();
        QName startName = startElement.getName();
        if (snippetName.equals(startName)) {
          handleSnippet(reader, startElement);
        } else if (extractedName.equals(startName)) {
          handleExtracted(reader, startElement);
        } else if (extractedNoneName.equals(startName)) {
          handleExtracted(reader, startElement);
        } else if (metadataName.equals(startName)) {
          handleMetadata(reader, startElement);
        } else if (similarName.equals(startName)) {
          handleSimilar(reader, startElement);
        } else if (relevanceInfoName.equals(startName)) {
          handleRelevanceInfo(reader, startElement);
        } else {
          break eventType;
        }

        // found result substructure, so cannot be a raw snippet
        if (eventBuf != null) {
          eventBuf = null;
        }

        break eventType;
      case XMLStreamConstants.END_ELEMENT:
        if (resultName.equals(event.asEndElement().getName())) {
          break events;
        }
        break eventType;
    }

    // buffer candidates for a raw snippet
    if (eventBuf != null) {
      eventBuf.add(event);
    }
  }

  // capture raw snippet
  if (eventBuf != null) {
    int first = tempEvents.size();
    tempEvents.addAll(eventBuf);
    addSnippet(new EventRange(first, tempEvents.size()));
  }
}
 
Example 19
Source File: StreamingXmlParser.java    From datacollector with Apache License 2.0 4 votes vote down vote up
XMLEvent read(XMLEventReader reader) throws XMLStreamException  {
  skipIgnorable(reader);
  return reader.nextEvent();
}
 
Example 20
Source File: ApplicationPolicyParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public List<ApplicationPolicy> parse(XMLEventReader xmlEventReader) throws XMLStreamException
{
   List<ApplicationPolicy> policies = new ArrayList<ApplicationPolicy>();
   while(xmlEventReader.hasNext())
   { 
       XMLEvent xmlEvent = xmlEventReader.nextEvent();
       int eventType = xmlEvent.getEventType();
       switch(eventType)
       {
           case XMLStreamConstants.START_ELEMENT:  
              StartElement appPolicyElement = (StartElement) xmlEvent;
              String elementName = StaxParserUtil.getStartElementName(appPolicyElement);
              if("application-policy".equals(elementName) == false)
                 throw StaxParserUtil.unexpectedElement(elementName, xmlEvent);
              //We got the application-policy element. It just has one attribute "name"
              Iterator<Attribute> attrs = appPolicyElement.getAttributes(); 
              String extendsName = null;
              String appPolicyName = null;
              
              while(attrs.hasNext())
              {
                 Attribute attribute = attrs.next();
                 QName attributeName = attribute.getName();
                 String attributeValue = StaxParserUtil.getAttributeValue(attribute);
                 
                 if("name".equals(attributeName.getLocalPart()))
                    appPolicyName = attributeValue; 
                 else if("extends".equals(attributeName.getLocalPart()))
                    extendsName = attributeValue;  
              }

              ApplicationPolicy applicationPolicy = new ApplicationPolicy(appPolicyName); 
              if(extendsName != null)
                 applicationPolicy.setBaseApplicationPolicyName(extendsName);
               
              route(xmlEventReader, applicationPolicy);
              policies.add(applicationPolicy); 
       } 
   }
   return policies;
}