|
11 | 11 | using System; |
12 | 12 | using System.Collections.Generic; |
13 | 13 | using System.IO; |
| 14 | +using System.Linq; |
14 | 15 | using System.Reflection; |
15 | 16 | using System.Text; |
16 | 17 | using System.Text.RegularExpressions; |
@@ -51,9 +52,9 @@ private static XDocument XDocumentFromReaderInternal(XmlReader reader, bool igno |
51 | 52 |
|
52 | 53 | public static XDocument XDocumentFromReader(XmlReader reader, bool ignoreComments = true) |
53 | 54 | => XDocumentFromReaderInternal(WrapXmlReader(reader, ignoreComments)); |
54 | | - |
| 55 | + |
55 | 56 | public static Task<XDocument> XDocumentFromReaderAsync(XmlReader reader, bool ignoreComments = true) |
56 | | - => Task.FromResult(XDocumentFromReaderInternal(WrapXmlReader(reader, ignoreComments, async:true))); |
| 57 | + => Task.FromResult(XDocumentFromReaderInternal(WrapXmlReader(reader, ignoreComments, async: true))); |
57 | 58 |
|
58 | 59 | /// <inheritdoc cref="JObjectFromReaderAsync(JsonReader)" /> |
59 | 60 | public static JObject JObjectFromReader(JsonReader reader) |
@@ -125,9 +126,9 @@ public static async Task<JObject> JObjectFromJsonTextAsync(string json) |
125 | 126 |
|
126 | 127 | public static XmlReader XmlReaderFromXmlText(string xml, bool ignoreComments = true) |
127 | 128 | => WrapXmlReader(XmlReader.Create(new StringReader(SerializationUtil.SanitizeXml(xml))), ignoreComments); |
128 | | - |
| 129 | + |
129 | 130 | public static Task<XmlReader> XmlReaderFromXmlTextAsync(string xml, bool ignoreComments = true) |
130 | | - => Task.FromResult(WrapXmlReader(XmlReader.Create(new StringReader(SerializationUtil.SanitizeXml(xml))), ignoreComments, async:true)); |
| 131 | + => Task.FromResult(WrapXmlReader(XmlReader.Create(new StringReader(SerializationUtil.SanitizeXml(xml))), ignoreComments, async: true)); |
131 | 132 |
|
132 | 133 | public static JsonReader JsonReaderFromJsonText(string json) |
133 | 134 | => JsonReaderFromTextReader(new StringReader(json)); |
@@ -262,7 +263,7 @@ public static XDocument WriteXmlToDocument(Action<XmlWriter> serializer) |
262 | 263 |
|
263 | 264 | return doc; |
264 | 265 | } |
265 | | - |
| 266 | + |
266 | 267 | public static async Task<XDocument> WriteXmlToDocumentAsync(Func<XmlWriter, Task> serializer) |
267 | 268 | { |
268 | 269 | var doc = new XDocument(); |
@@ -472,8 +473,15 @@ public static string[] RunFhirXhtmlSchemaValidation(XDocument doc) |
472 | 473 | if (!doc.Root.AtXhtmlDiv()) |
473 | 474 | return new[] { $"Root element of XHTML is not a <div> from the XHTML namespace ({XmlNs.XHTML})." }; |
474 | 475 |
|
| 476 | + if (!hasContent(doc.Root)) |
| 477 | + return new[] { $"The narrative SHALL have some non-whitespace content." }; |
| 478 | + |
475 | 479 | doc.Validate(_xhtmlSchemaSet.Value, (s, a) => result.Add(a.Message)); |
476 | 480 | return result.ToArray(); |
| 481 | + |
| 482 | + // content consist of xml elements with non-whitespace content (text or an image) |
| 483 | + static bool hasContent(XElement el) |
| 484 | + => el.DescendantsAndSelf().Any(e => !string.IsNullOrWhiteSpace(e.Value) || e.Name.LocalName == "img"); |
477 | 485 | } |
478 | 486 |
|
479 | 487 | private static Lazy<XmlSchemaSet> _xhtmlSchemaSet = new Lazy<XmlSchemaSet>(compileXhtmlSchema, true); |
|
0 commit comments