Browse Source

XML can be further than one line down

Piotr Czajkowski 3 years ago
parent
commit
a541ca3891
1 changed files with 11 additions and 14 deletions
  1. 11 14
      PSDText/PSDText.cs

+ 11 - 14
PSDText/PSDText.cs

@@ -18,23 +18,20 @@ namespace PSDText
             var sb = new StringBuilder(1000);
             using (var sr = new StreamReader(path))
             {
-                sr.ReadLine(); //skip first line
-                    
-                var line = sr.ReadLine();
-                if (string.IsNullOrWhiteSpace(line))
-                    return string.Empty;
-
-                var read = line.StartsWith("<x:xmpmeta");
-                while (read)
+                var read = false;
+                while (true)
                 {
-                    if (line.StartsWith("</x:xmpmeta>"))
-                        read = false;
-
-                    sb.Append(line);
-
-                    line = sr.ReadLine();
+                    var line = sr.ReadLine();
                     if (string.IsNullOrWhiteSpace(line))
                         return sb.ToString();
+
+                    if (line.StartsWith("<x:xmpmeta"))
+                        read = true;
+
+                    if (read) sb.Append(line);
+
+                    if (line.StartsWith("</x:xmpmeta>"))
+                        break;
                 }
             }