From 67c7b6e78aa9c465b5ab9d166905f7f372aea01c Mon Sep 17 00:00:00 2001 From: schrom01 Date: Tue, 20 Sep 2022 21:51:29 +0200 Subject: [PATCH] =?UTF-8?q?Aufgabe=204=20gel=C3=B6st.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch/zhaw/ads/ADS1_4_test.java | 3 +- src/ch/zhaw/ads/WellformedXmlServer.java | 37 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/ch/zhaw/ads/ADS1_4_test.java b/src/ch/zhaw/ads/ADS1_4_test.java index 6ed32c0..fcb48d2 100644 --- a/src/ch/zhaw/ads/ADS1_4_test.java +++ b/src/ch/zhaw/ads/ADS1_4_test.java @@ -1,4 +1,4 @@ -/* + package ch.zhaw.ads; import org.junit.jupiter.api.BeforeEach; @@ -34,4 +34,3 @@ public class ADS1_4_test { } } -*/ \ No newline at end of file diff --git a/src/ch/zhaw/ads/WellformedXmlServer.java b/src/ch/zhaw/ads/WellformedXmlServer.java index d6425a8..cbe1ac5 100644 --- a/src/ch/zhaw/ads/WellformedXmlServer.java +++ b/src/ch/zhaw/ads/WellformedXmlServer.java @@ -8,6 +8,43 @@ public class WellformedXmlServer implements CommandExecutor { } public boolean checkWellformed(String arg) { + Stack stack = new ListStack(); + char[] chars = arg.toCharArray(); + for(int i = 0; i < chars.length; i++){ + if(chars[i] == '<') { + boolean closing = false; + i++; + if(chars[i] == '/'){ + closing = true; + i++; + } + String tag = ""; + while(chars[i] != '>' && chars[i] != ' '){ + tag = tag + chars[i]; + i++; + } + if(tag.charAt(tag.length() - 1) == '/') { + } + else if (closing){ + if(!tag.equals(stack.pop())){ + return false; + } + } else { + stack.push(tag); + } + } + } + if(stack.isEmpty()){ + return true; + } else { + return false; + } } + + private String getNextToken(){ + return null; + } + + } \ No newline at end of file