blob: 458e6fa298287b9e4efc553e3ad718a987673ed7 [file] [log] [blame]
Paul Duffin7fc0b452015-11-10 17:45:15 +00001/*
2 * Copyright (C) 2010 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.caliper;
18
19import com.google.common.collect.ImmutableList;
20import com.google.common.collect.ImmutableMap;
21
22import org.w3c.dom.Attr;
23import org.w3c.dom.Element;
24import org.w3c.dom.NamedNodeMap;
25import org.w3c.dom.Node;
26import org.w3c.dom.NodeList;
27
28public final class XmlUtils {
29 public static ImmutableList<Node> childrenOf(Node node) {
30 NodeList children = node.getChildNodes();
31 ImmutableList.Builder<Node> result = ImmutableList.builder();
32 for (int i = 0, size = children.getLength(); i < size; i++) {
33 result.add(children.item(i));
34 }
35 return result.build();
36 }
37
38 public static ImmutableMap<String, String> attributesOf(Element element) {
39 NamedNodeMap map = element.getAttributes();
40 ImmutableMap.Builder<String, String> result = ImmutableMap.builder();
41 for (int i = 0, size = map.getLength(); i < size; i++) {
42 Attr attr = (Attr) map.item(i);
43 result.put(attr.getName(), attr.getValue());
44 }
45 return result.build();
46 }
47
48 private XmlUtils() {}
49}