3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 package de.dhbwloe.campusapp.network;
17 import android.os.Bundle;
18 import android.util.Log;
19 import android.util.Xml;
21 import java.util.ArrayList;
24 * Created by pk910 on 22.01.2016.
26 public class XmlEntry {
27 public static XmlEntry FindXmlEntryByName(XmlEntry root, String name) {
28 if(root.getName().equalsIgnoreCase(name))
30 for(XmlEntry entry : root.getChildren()) {
31 entry = FindXmlEntryByName(entry, name);
38 public static XmlEntry[] FindXmlEntriesByName(XmlEntry root, String name) {
39 Log.i("XMLFind", "Search "+name+" have: "+root.getName());
40 if(root.getName().equalsIgnoreCase(name))
41 return new XmlEntry[] { root };
43 ArrayList<XmlEntry> entries = new ArrayList<XmlEntry>();
44 for(XmlEntry entry : root.getChildren()) {
45 XmlEntry[] centries = FindXmlEntriesByName(entry, name);
46 for(XmlEntry centry : centries)
49 XmlEntry[] entriesArr = new XmlEntry[entries.size()];
50 entriesArr = entries.toArray(entriesArr);
57 private ArrayList<XmlEntry> children = new ArrayList<XmlEntry>();
58 private Bundle attributes = new Bundle();
60 public XmlEntry(String name) {
64 public void setValue(String value) {
68 public String getName() {
72 public String getValue() {
76 public void addChild(XmlEntry child) {
80 public XmlEntry[] getChildren() {
81 XmlEntry childs[] = new XmlEntry[children.size()];
82 childs = children.toArray(childs);
86 public void setAttribute(String name, String value) {
87 attributes.putString(name, value);
90 public void setAttributes(Bundle bundle) {
91 attributes.putAll(bundle);
94 public Bundle getAttributes() {
98 public String getAttribute(String name) {
99 return attributes.getString(name);