// Transform may close input reader and replace it with a new one. // To emphasize this we pass xmlReader by ref.s private static void Transform(ref XmlReader xmlReader) { for (;;) { while (xmlReader.NodeType != XmlNodeType.Element && xmlReader.Read()) { ; // skip to the first element } string xslt = CircuitProject.FindTransformation(xmlReader.NamespaceURI); if (xslt == null) { throw new CircuitException(Cause.UnknownVersion, Properties.Resources.ErrorUnknownVersion); } if (xslt.Length == 0) { // No transform needed. We are at the current version. return; } XmlHelper.Transform(xslt, ref xmlReader); } }
public static bool CanPaste(string text) { // To reduce number of exceptions from XML reader lets check there if some familiar text is in the string. // Lets not use namespace as it will prevent pasting of old versions of the XML. if (!string.IsNullOrEmpty(text) && text.Contains("<lc:CircuitProject")) { try { using (XmlReader xmlReader = XmlHelper.CreateReader(new StringReader(text))) { string rootName = xmlReader.NameTable.Add("CircuitProject"); while (xmlReader.NodeType != XmlNodeType.Element && xmlReader.Read()) { ; // skip to the first element } return( XmlHelper.AreEqualAtoms(rootName, xmlReader.LocalName) && // We are at CircuitProject element CircuitProject.FindTransformation(xmlReader.NamespaceURI) != null // and it is in known namespace ); } } catch {} } return(false); }