xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
477 stars 171 forks source link

IFCXml File with empty header throws exception #555

Closed imsmk closed 3 months ago

imsmk commented 3 months ago

load ifcxml with empty header elements throws exception 'Unexpected node type'

Assemblies and versions affected:

*Xbim.Essentials 5 and 6

Steps (or code) to reproduce the issue:

try to load an ifc xml file with this header

<?xml version="1.0" encoding="utf-8"?>
<ifcXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.buildingsmart-tech.org/ifcXML/IFC4/Add2">
  <header>
    <name>Test</name>
    <time_stamp>2023-04-01T00:00:00+02:00</time_stamp>
    <author></author>
  </header>
  ...

Author Element is empty and the GetTextFromElement function of XbimXmlReader throws the error "Unexpected node type"

andyward commented 3 months ago

Thanks @imsmk - I don't suppose you had a look at a potential fix? Happy to take a PR. I'd imagine it's a fairly simple guard needed in this area: https://github.com/xBimTeam/XbimEssentials/blob/4ed33f7a0427ea91bc7825810c381779ecf5053c/Xbim.IO.MemoryModel/Xml/XbimXmlReader3.cs#L857

(...and maybe in the other cases in that switch). XbimXmlReader4 may also need review.

andyward commented 3 months ago

Merged. Thanks again @imsmk