Fork me on GitHub
reqifsharp - .NET ReqIF Reading and Writing

Introduction

A ReqIF document is an XML document that is structured according to the OMG ReqIF specification and is used for the exchange of requirements that have been authored in different tools such as the CDP4™, IBM Rational DOORS and many others. The ReqIF specification includes the ReqIF XML schema. The ReqIF makes use of certain XHTML modules that provide formatting for text such as tabular data, bold, italics etc. The ReqIFSharp library can be used with and without XML Schema validation. ReqIFSharp currently targets the .NET Framework 4.5 and netstandard 1.6. When using netstandard 1.6 it does not support XML Schema validation. We are investigation if and how we can support schema validation in netstandard 1.6 as well, or whether we will only do that in an upcoming update for netstandard 2.0

The two interfaces that are used the most in the reqifharp library are the IReqIFDeserializer interface and the IReqIFSerializer interface. The IReqIFDeserializer interface is used to deserialze a ReqIF document and create a ReqIF obejct, while the IReqIFSerializer is used to serialize a ReqIF object.

Deserialization

An existing ReqIF document can be deserialized to an object graph using the ReqIFDeserializer class that implements the IReqIFDeserializer interface. The IReqIFDeserializer interface exposes one method, the Deserialize method. The Deserialize method returns a ReqIF object that is the root node of a ReqIF document. The following code snippet demonstrates how to deserialize a ReqIF document without XML schema validation.

                    
        public void Deserialize()
        {
            var path = "some-file-path.reqif";                        
            var deserializer = new ReqIFDeserializer();
            var reqif = deserializer.Deserialize(path);
            var header = reqif.TheHeader.FirstOrDefault();;
            var content = reqif.CoreContent.FirstOrDefault();
        }
                    
                

The following code snippet demonstrates how to deserialize using XML schema validation.

                    
        public void Deserialize()
        {
            var path = "some-file-path.reqif";                        
            var deserializer = new ReqIFDeserializer();
            var reqif = deserializer.Deserialize(path, true, this.ValidationEventHandler);
            var header = reqif.TheHeader.FirstOrDefault();;
            var content = reqif.CoreContent.FirstOrDefault();
        }

        public void ValidationEventHandler(object sender, ValidationEventArgs validationEventArgs)
        {
            throw validationEventArgs.Exception;
        }
                    
                

Serialization

The ReqIFSerializer class that implements the IReqIFSerializer interface is used to serialize a requirements specification to a reqif document. An ReqIF object, and it's content, can be constructed using the ReqIFSharp library. The following snippet demonstrates how this can be achieved.

                    
        public void Serialize()
        {
            var reqif = new ReqIF();
            this.reqIF.Lang = "en";

            var header = new ReqIFHeader()
            {
                Comment = "this is a comment",
                CreationTime = DateTime.Parse("2015-12-01"),
                Identifier = "reqifheader",
                RepositoryId = "a repos id",
                ReqIFToolId = "reqifsharp",
                ReqIFVersion = "1.0",
                SourceToolId = "reqifsharp",
                Title = "this is a title"
            };

            this.reqIF.TheHeader.Add(header);

            var reqIfContent = new ReqIFContent();
            this.reqIF.CoreContent.Add(reqIfContent);

            var resultFileUri = "some-file-path.reqif";
            var serializer = new ReqIFSerializer(false);
            serializer.Serialize(this.reqIF, resultFileUri , null);
        }
                    
                

For a more detailed explanation of the ReqIFContent of a ReqIF object please refer to the online documentation.