public void ReadXml(System.Xml.XmlReader reader) { bool wasEmpty = reader.IsEmptyElement; bool first = true; reader.Read(); if (wasEmpty) { return; } while (reader.NodeType != System.Xml.XmlNodeType.EndElement) { reader.Read(); if (reader.IsEmptyElement) { reader.Skip(); reader.Skip(); reader.Skip(); reader.Skip(); reader.ReadEndElement(); reader.MoveToContent(); continue; } reader.ReadStartElement("id"); int keyValue = reader.ReadContentAsInt(); SkeletonJoint key; try { key = GetTranslation(keyValue).joint_type; } catch (Exception) { key = SkeletonJoint.Invalid; } reader.ReadEndElement(); float confidence = 0.0f; if (reader.Name.Equals("confidence")) { reader.Read(); confidence = reader.ReadContentAsFloat(); reader.ReadEndElement(); } reader.ReadStartElement("x"); float x = reader.ReadContentAsFloat(); reader.ReadEndElement(); reader.ReadStartElement("y"); float y = reader.ReadContentAsFloat(); reader.ReadEndElement(); float z = 0.0f; if (first) { if (reader.Name.Equals("z")) { _is3DData = true; } else { _is3DData = false; } first = false; } if (reader.Name.Equals("z")) { reader.ReadStartElement("z"); z = reader.ReadContentAsFloat(); reader.ReadEndElement(); if (!_is3DData) { throw new Exception("Inconsistent 2D/3D data format."); } } else { if (_is3DData) { throw new Exception("Inconsistent 2D/3D data format."); } } SkeletonJointPosition value = new SkeletonJointPosition(); value.Confidence = confidence; value.Position = new Point3D(x, y, z); if (key != SkeletonJoint.Invalid) { this.Add(key, value); } reader.ReadEndElement(); reader.MoveToContent(); } }