예제 #1
0
        public void WitsmlParser_RemoveEmptyElements_Removes_Empty_Elements_From_Elements()
        {
            var xdoc = WitsmlParser.Parse(_wellXml);

            Assert.IsNotNull(xdoc.Root);

            var elemPurposeWell     = new XElement(xdoc.Root.GetDefaultNamespace() + "purposeWell");
            var elemStatusWell      = new XElement(xdoc.Root.GetDefaultNamespace() + "statusWell", "plugged and abandoned");
            var elemGroundElevation = new XElement(xdoc.Root.GetDefaultNamespace() + "groundElevation");
            var nil = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance").GetName("nil");

            elemGroundElevation.Add(new XAttribute(nil, true));

            xdoc.Root.Elements().FirstOrDefault()?.Add(elemPurposeWell);
            xdoc.Root.Elements().FirstOrDefault()?.Add(elemStatusWell);
            xdoc.Root.Elements().FirstOrDefault()?.Add(elemGroundElevation);

            WitsmlParser.RemoveEmptyElements(xdoc.Root);
            var welllist = EnergisticsConverter.XmlToObject <WellList>(xdoc.Root.ToString());

            Assert.IsNotNull(welllist.Well[0].StatusWell);
            Assert.IsNull(welllist.Well[0].PurposeWell);
            Assert.IsNull(welllist.Well[0].GroundElevation);
        }