Guest User

Untitled

a guest
Jul 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. package aufgabe2;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.util.Scanner;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9.  
  10.  
  11. public class Scantest {
  12.  
  13. /**
  14. * @param args
  15. * @throws FileNotFoundException
  16. */
  17. public static void main(String[] args) throws FileNotFoundException {
  18. // TODO Auto-generated method stub
  19.  
  20. BestellungListe b1 = scanMatch("src/aufgabe2/Bestellungen.xml", "12");
  21. // Bestellung r1 = new Bestellung("12");
  22. System.out.println(b1);
  23.  
  24. }
  25.  
  26. private static BestellungListe scanMatch(String filename, String bestnr)
  27. throws FileNotFoundException {
  28. BestellungListe bl = new BestellungListe();
  29.  
  30. Pattern kdptrn = Pattern.compile("\\s*<kd nr=\"(.*?)\"");
  31. Pattern vptrn = Pattern.compile("\\s*<vertrag nr=\"(.*?)\" cat=\"(.*?)\" datum=\"(.*?)\">(.*?)</vertrag>");
  32. Scanner scanner = new Scanner(new File(filename));
  33.  
  34. Pattern gesamt = Pattern.compile("\\s*</kd>\\s*");
  35. scanner.useDelimiter(gesamt);
  36.  
  37. while (scanner.hasNext()) {
  38. String str = scanner.next();
  39.  
  40. Matcher kdmt = kdptrn.matcher(str);
  41. Matcher vmt = vptrn.matcher(str);
  42.  
  43. if (kdmt.find()) {
  44. String kdnr = kdmt.group(1).trim();
  45.  
  46. while (vmt.find()) {
  47. String vnr = vmt.group(1).trim();
  48. String cat = vmt.group(2).trim();
  49. String datum = vmt.group(3).trim();
  50. String title = vmt.group(4).trim();
  51.  
  52. System.out.println(vnr);
  53. System.out.println(cat);
  54. System.out.println(datum);
  55. System.out.println(title);
  56. }
  57.  
  58. } else {
  59. throw new RuntimeException("no kd nr");
  60. }
  61.  
  62.  
  63. System.out.println(kdmt);
  64.  
  65. }
  66.  
  67. return bl;
  68.  
  69. }
  70. }
Add Comment
Please, Sign In to add comment