diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-02-18 14:17:18 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-02-18 14:17:18 +0100 |
commit | b74a054bd7e7538594824445a0bc666ebb337689 (patch) | |
tree | 12de69267471c6f6b42e05a94a60128d41895c1d | |
parent | 64705a0c297121c6011e91c3b40d66fbcc2c160f (diff) |
added support for primitive subtree fields in XMLOutput.
-rw-r--r-- | src/plugins/xml/XmlOutput.cpp | 3 | ||||
-rw-r--r-- | test/plugins/xml/XmlOutputTest.cpp | 40 |
2 files changed, 41 insertions, 2 deletions
diff --git a/src/plugins/xml/XmlOutput.cpp b/src/plugins/xml/XmlOutput.cpp index 37d95ec..85885bc 100644 --- a/src/plugins/xml/XmlOutput.cpp +++ b/src/plugins/xml/XmlOutput.cpp @@ -137,8 +137,7 @@ void XmlTransformer::transformChildren(DocumentEntity *parentEntity, Rooted<FieldDescriptor> fieldDesc = fieldDescs[f]; // if this is not the default field create an intermediate node for it. Rooted<Element> par = parent; - if (fieldDesc->getFieldType() != FieldDescriptor::FieldType::TREE && - !fieldDesc->isPrimitive()) { + if (fieldDesc->getFieldType() != FieldDescriptor::FieldType::TREE) { par = Rooted<Element>{new Element(mgr, parent, fieldDesc->getName())}; parent->addChild(par); diff --git a/test/plugins/xml/XmlOutputTest.cpp b/test/plugins/xml/XmlOutputTest.cpp index 403078d..fcf72d2 100644 --- a/test/plugins/xml/XmlOutputTest.cpp +++ b/test/plugins/xml/XmlOutputTest.cpp @@ -107,5 +107,45 @@ TEST(DemoHTMLTransformer, AnnotationProcessing) "><book:text>blub</book:text><a:end:emphasized/" "><book:text>bla</book:text><a:end:strong/>") != std::string::npos); } + +TEST(DemoHTMLTransformer, PrimitiveSubtreeFields) +{ + // Construct Manager + TerminalLogger logger{std::cerr, true}; + Manager mgr{1}; + Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)}; + // Construct a simple domain. + Rooted<Domain> domain{new Domain(mgr, sys, "myDomain")}; + + Rooted<StructuredClass> A{new StructuredClass( + mgr, "A", domain, Cardinality::any(), nullptr, false, true)}; + Rooted<FieldDescriptor> A_a = + A->createPrimitiveFieldDescriptor(sys->getStringType(), logger, + FieldDescriptor::FieldType::SUBTREE, + "a").first; + Rooted<FieldDescriptor> A_b = + A->createPrimitiveFieldDescriptor(sys->getStringType(), logger, + FieldDescriptor::FieldType::SUBTREE, + "b").first; + Rooted<FieldDescriptor> A_main = + A->createPrimitiveFieldDescriptor(sys->getStringType(), logger).first; + ASSERT_TRUE(domain->validate(logger)); + // Construct a document for it. + Rooted<Document> doc{new Document(mgr, "myDoc")}; + Rooted<StructuredEntity> A_impl = doc->createRootStructuredEntity(A); + A_impl->createChildDocumentPrimitive("test_a", "a"); + A_impl->createChildDocumentPrimitive("test_b", "b"); + A_impl->createChildDocumentPrimitive("test"); + ASSERT_TRUE(doc->validate(logger)); + // now transform this document. + ResourceManager dummy; + XmlTransformer transformer; + std::stringstream out; + transformer.writeXml(doc, out, logger, dummy, false); + const std::string res = out.str(); + ASSERT_TRUE( + res.find("<myDomain:A><a>test_a</a><b>test_b</b>test</myDomain:A>") != + std::string::npos); +} } }
\ No newline at end of file |