Parse the XML for a collection as returned by getInfo call.

@param collectionElement
@return
971763
private Collection parseCollection(Element collectionElement) {

        Collection collection = new Collection();
        collection.setId(collectionElement.getAttribute("id"));
        collection.setServer(collectionElement.getAttribute("server"));
        collection.setSecret(collectionElement.getAttribute("secret"));
        collection.setChildCount(collectionElement.getAttribute("child_count"));
        collection.setIconLarge(collectionElement.getAttribute("iconlarge"));
        collection.setIconSmall(collectionElement.getAttribute("iconsmall"));
        collection.setDateCreated(collectionElement.getAttribute("datecreate"));
        collection.setTitle(XMLUtilities.getChildValue(collectionElement, "title"));
        collection.setDescription(XMLUtilities.getChildValue(collectionElement, "description"));

        Element iconPhotos = XMLUtilities.getChild(collectionElement, "iconphotos");
        if (iconPhotos != null) {
            NodeList photoElements = iconPhotos.getElementsByTagName("photo");
            for (int i = 0; i < photoElements.getLength(); i++) {
                Element photoElement = (Element) photoElements.item(i);
                collection.addPhoto(PhotoUtils.createPhoto(photoElement));
            }
        }

        return collection;
    }
306551
private XmlMessageValidationContext getXmlMessageValidationContext(Element messageElement) {
        XmlMessageValidationContext context = new XmlMessageValidationContext();

        if (messageElement != null) {
            addSchemaInformationToValidationContext(messageElement, context);

            Set<String> ignoreExpressions = new HashSet<String>();
            List<?> ignoreElements = DomUtils.getChildElementsByTagName(messageElement, "ignore");
            for (Iterator<?> iter = ignoreElements.iterator(); iter.hasNext();) {
                Element ignoreValue = (Element) iter.next();
                ignoreExpressions.add(ignoreValue.getAttribute("path"));
            }
            context.setIgnoreExpressions(ignoreExpressions);

            parseNamespaceValidationElements(messageElement, context);

            //Catch namespace declarations for namespace context
            Map<String, String> namespaces = new HashMap<String, String>();
            List<?> namespaceElements = DomUtils.getChildElementsByTagName(messageElement, "namespace");
            if (namespaceElements.size() > 0) {
                for (Iterator<?> iter = namespaceElements.iterator(); iter.hasNext();) {
                    Element namespaceElement = (Element) iter.next();
                    namespaces.put(namespaceElement.getAttribute("prefix"), namespaceElement.getAttribute("value"));
                }
                context.setNamespaces(namespaces);
            }
        }

        return context;
    }
1118810
protected static Element parse(InputStream stream) throws IOException {
        try {
            return DBF.get().newDocumentBuilder().parse(stream).getDocumentElement();
        }
        catch (SAXException | ParserConfigurationException e) {
            throw new IOException("parsing stream failed", e);
        }
        finally {
            stream.close();
        }
    }
181963
def makeServiceDocXML(title, collections):
    

    serviceTag = etree.Element("service")
    workspaceTag = etree.SubElement(serviceTag, "workspace")
    titleTag = etree.SubElement(workspaceTag, ATOM + "title", nsmap=ATOM_NSMAP)
    titleTag.text = title
    for collection in collections:
        collectionTag = etree.SubElement(workspaceTag, "collection")
        if 'href' in collection:
            collectionTag.set("href", collection['href'])
        if 'title' in collection:
            colTitleTag = etree.SubElement(
                collectionTag, ATOM + "title", nsmap=ATOM_NSMAP
            )
            colTitleTag.text = collection['title']
        if 'accept' in collection:
            acceptTag = etree.SubElement(collectionTag, "accept")
            acceptTag.text = collection['accept']
    return serviceTag
467663
public DiffNode getChild(final ElementSelector elementSelector)
	{
		if (elementSelector instanceof CollectionItemElementSelector && childIdentityStrategy != null)
		{
			return children.get(((CollectionItemElementSelector) elementSelector).copyWithIdentityStrategy(childIdentityStrategy));
		}
		else
		{
			return children.get(elementSelector);
		}
	}
686676
@Override
  protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException {

    // Find out if the our namespace already has been defined, and if so, get the prefix.
    //
    final String namespace = CurrentAddressType.TYPE_NAME.getNamespaceURI();
    Optional<String> _prefix = xmlObject.getNamespaceManager()
      .getNamespaces()
      .stream()
      .filter(n -> namespace.equals(n.getNamespaceURI()))
      .map(n -> n.getNamespacePrefix())
      .findFirst();
    String prefix = _prefix.isPresent() ? _prefix.get() : CurrentAddressType.TYPE_NAME.getPrefix();
    
    StringBuilder sb = new StringBuilder();

    final List<XMLObject> childXMLObjects = xmlObject.getOrderedChildren();
    if (childXMLObjects != null && childXMLObjects.size() > 0) {
      for (final XMLObject childXMLObject : childXMLObjects) {
        if (childXMLObject == null) {
          continue;
        }
        if (!(childXMLObject instanceof XSString)) {
          throw new MarshallingException("Unexpected type of child element - " + childXMLObject.getClass().getName());
        }
        XSString childString = (XSString) childXMLObject;
        if (childString.getValue() == null) {
          continue;
        }
        String localPart = childString.getElementQName().getLocalPart();
        sb.append(String.format("<%s:%s>%s</%s:%s>", prefix, localPart, childString.getValue(), prefix, localPart));
      }
    }
    if (sb.length() > 0) {
      byte[] bytes;
      try {
        bytes = sb.toString().getBytes("UTF-8");
      }
      catch (UnsupportedEncodingException e) {
        throw new MarshallingException(e);
      }
      String base64String = Base64Support.encode(bytes, true);
      ElementSupport.appendTextContent(domElement, base64String);
    }
  }
210174
public static Object selectObject(Node node, String xpathQuery) {
        Object result = node.selectObject(xpathQuery);
        if (result != null && result instanceof Collection && ((Collection) result).isEmpty()) {
            return null;
        } else {
            return result;
        }
    }
1353145
public Object parseArrayElement(Element arrayEle, BeanDefinition bd) {
    String elementType = arrayEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
    NodeList nl = arrayEle.getChildNodes();
    ManagedArray target = new ManagedArray(elementType, nl.getLength());
    target.setSource(extractSource(arrayEle));
    target.setElementTypeName(elementType);
    target.setMergeEnabled(parseMergeAttribute(arrayEle));
    parseCollectionElements(nl, target, bd, elementType);
    return target;
  }
495696
private Element getChildElement(Element parent) {
	NodeList list = parent.getChildNodes();
	int len = list.getLength();
	for (int i = 0; i < len; i++) {
	    Node node = list.item(i);
	    if (node instanceof Element) {
		return (Element) node;
	    }
	}
	return null;
    }
282911
public List<Object> parseListElement(Element collectionEle, BeanDefinition bd) {
    String defaultElementType = collectionEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
    NodeList nl = collectionEle.getChildNodes();
    ManagedList<Object> target = new ManagedList<Object>(nl.getLength());
    target.setSource(extractSource(collectionEle));
    target.setElementTypeName(defaultElementType);
    target.setMergeEnabled(parseMergeAttribute(collectionEle));
    parseCollectionElements(nl, target, bd, defaultElementType);
    return target;
  }
141057
@Override
	public <L extends Collection<E>> L parseCollection(BinderContext context, ParserWrapper parserWrapper, L collection)  throws Exception {
		switch (context.getSupportedFormat()) {
		case XML: {
			throw (new KriptonRuntimeException(context.getSupportedFormat() + " context does not support direct collection persistance"));
		}
		default: {
			JacksonWrapperParser wrapperParser = (JacksonWrapperParser) parserWrapper;
			JsonParser parser = wrapperParser.jacksonParser;

			try {
				collection.clear();

				if (parser.nextToken() != JsonToken.START_ARRAY) {
					throw (new KriptonRuntimeException("Invalid input format"));
				}
				if (context.getSupportedFormat().onlyText) {
					while (parser.nextToken() != JsonToken.END_ARRAY) {
						collection.add(parseOnJacksonAsString(parser));
					}
				} else {
					while (parser.nextToken() != JsonToken.END_ARRAY) {
						collection.add(parseOnJackson(parser));
					}
				}
				return collection;
			} catch (IOException e) {
				e.printStackTrace();
				throw (new KriptonRuntimeException(e));
			}
		}
		}
	}
1266099
def parse_bundle_collection(body)
        dom = parse_and_validate_response(body, :root_name => 'bundles')
        dom.root.elements.collect('bundle') { |xml| Bundle.from_rexml(xml) }
      end
305177
private static List<Element> getElements(Document document) {
        List<Element> result = new ArrayList<Element>();

        Element root = document.getDocumentElement();
        NodeList nodeList = root.getChildNodes();
        Node node = null;
        Element nodeElement = null;

        for (int i = 0; i < nodeList.getLength(); i++) {
            node = nodeList.item(i);

            if (node instanceof Element) {
                nodeElement = (Element) node;

                if (nodeElement.hasAttribute("id") == false) {
                    throw new MjdbcRuntimeException("Found XML element without ID attribute. Parsing is interrupted");
                } else {
                    result.add(nodeElement);
                }
            }
        }

        return result;
    }
135824
public static Element parse(InputStream xmlStream, DocumentBuilder builder) throws IOException
   {
      try
      {
         Document doc;
         synchronized (builder) //synchronize to prevent concurrent parsing on the same DocumentBuilder
         {
            doc = builder.parse(xmlStream);
         }
         return doc.getDocumentElement();
      }
      catch (SAXException se)
      {
         throw new IOException(se.toString());
      }
      finally
      {
         xmlStream.close();
      }
   }
844737
def xmltreefromfile(filename):
    """"""
    try:
        return ElementTree.parse(filename, ElementTree.XMLParser(collect_ids=False))
    except TypeError:
        return ElementTree.parse(filename, ElementTree.XMLParser())
190848
public static XElement parseXML(XMLStreamReader in) throws XMLStreamException {
        XElement root = parseXMLFragment(in);
        in.close();
        return root;
    }
194438
public static Collection toCollection(String input, Class<?> collectionClass, Class<?> genericClass,
            String mediaType)
    {

        try
        {
            if (MediaType.APPLICATION_XML.equals(mediaType))
            {
                Collection c = (Collection) collectionClass.newInstance();
                if (input.startsWith("<?xml"))
                {
                    input = input.substring(input.indexOf(">") + 1, input.length());
                }

                input = input.replaceAll("<" + genericClass.getSimpleName().toLowerCase() + "s>", "");

                while (!input.equals(""))
                {
                    int i = input.indexOf("</" + genericClass.getSimpleName().toLowerCase() + ">");
                    String s = input.substring(0, i + 3 + genericClass.getSimpleName().length());
                    input = input.substring(i + 3 + genericClass.getSimpleName().length(), input.length());
                    Object o = JAXBUtils.toObject(StreamUtils.toInputStream(s), genericClass, mediaType);
                    c.add(o);
                }
                return c;

            }
            else if (MediaType.APPLICATION_JSON.equals(mediaType))
            {
                
                    return  JAXBUtils.mapper.readValue(input, JAXBUtils.mapper.getTypeFactory()
                                        .constructCollectionType((Class<? extends Collection>) collectionClass, genericClass));
               
                
            }
            return null;
        }
        catch (InstantiationException e)
        {
            log.error("Error during translation, Caused by:" + e.getMessage() + ", returning null");
            return null;
        }
        catch (IllegalAccessException e)
        {
            log.error("Error during translation, Caused by:" + e.getMessage() + ", returning null");
            return null;
        } catch (JsonParseException e) {
            log.error("Error during translation, Caused by:" + e.getMessage() + ", returning null");
            return null;
        } catch (JsonMappingException e) {
            log.error("Error during translation, Caused by:" + e.getMessage() + ", returning null");
            return null;
        } catch (IOException e) {
            log.error("Error during translation, Caused by:" + e.getMessage() + ", returning null");
            return null;
        }
    }