private static GenericXMLElement parseElement( XMLStreamReader xmlStream ) throws IllegalArgumentException, XMLStreamException { Map<QName, PrimitiveValue> attrs = parseAttrs( xmlStream ); List<TypedObjectNode> children = new ArrayList<TypedObjectNode>(); while ( xmlStream.next() != END_ELEMENT ) { int eventType = xmlStream.getEventType(); if ( eventType == START_ELEMENT ) { children.add( parseElement( xmlStream ) ); } else if ( eventType == CHARACTERS || eventType == CDATA ) { children.add( new PrimitiveValue( xmlStream.getText() ) ); } } return new GenericXMLElement( xmlStream.getName(), null, attrs, children ); }
private static Literal<?> parseLiteral( XMLStreamReader xmlStream ) throws XMLStreamException { QName type = getAttributeValueAsQName( xmlStream, null, "type", null ); if ( type != null ) { LOG.warn( "Literal with type attribute. Not respecting type hint (needs implementation)." ); } Map<QName, PrimitiveValue> attrs = parseAttrs( xmlStream ); List<TypedObjectNode> children = new ArrayList<TypedObjectNode>(); while ( xmlStream.next() != END_ELEMENT ) { int eventType = xmlStream.getEventType(); if ( eventType == START_ELEMENT ) { checkIfCurrentStartElementIsGmlGeometry( xmlStream ); children.add( parseElement( xmlStream ) ); } else if ( eventType == CHARACTERS || eventType == CDATA ) { children.add( new PrimitiveValue( xmlStream.getText() ) ); } } // TODO what about well-known complex elements (e.g. geometries)? TypedObjectNode value = null; if ( attrs.isEmpty() && children.size() == 1 ) { value = children.get( 0 ); } else if ( attrs.isEmpty() && children.isEmpty() ) { value = new PrimitiveValue( "" ); } else { value = new GenericXMLElement( null, null, attrs, children ); } return new Literal<TypedObjectNode>( value, type ); }