Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package xmlvalidator;
- import java.util.regex.*;
- public class Main {
- public static final String bean = "<!-- smuck --> <xml version=\"boodam\"> <person> <firstname>Joe</firstname> <lastname>Walnes</lastname>"
- + "<phone> <code>123</code> <number>1234-456</number> </phone> <fax> <code>123</code>"
- + "<number>9999-999</number> </fax> </person>";
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- BasicStringStack bob = new BasicStringStack();
- Pattern openPat = Pattern.compile("<(?!xml)[^-!/<>]+>");
- Pattern closePat = Pattern.compile("</[^<>]+>");
- Matcher openMat = openPat.matcher(bean);
- Matcher closeMat = closePat.matcher(bean);
- // String[] ray = bean.split("\\s+");
- // p(bean.replaceAll("<[^(xml)/<>]+>", " <openTag> "));
- // p(bean.replaceAll("</[^<>]+>", " </closeTag> "));
- while (openMat.find()) {
- p("Found: " + openMat.group());
- bob.push(openMat.group());
- // if(bob.peek(bob.getCount()-1)).equals(anObject)
- // p(bob.getCount());
- }
- int c = bob.getCount();
- for(int i = 0; i < c; i++){
- p(i + " " + bob.peek(i));
- }
- }
- public static <E> void p(E e) {
- System.out.println(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement