From: Oleg T. <he...@us...> - 2005-11-12 15:44:13
|
Update of /cvsroot/mvp-xml/Common/v2/src/Xsl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2184/v2/src/Xsl Modified Files: XslReader.cs Log Message: Index: XslReader.cs =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/src/Xsl/XslReader.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- XslReader.cs 7 Nov 2005 13:58:19 -0000 1.1 +++ XslReader.cs 12 Nov 2005 15:44:06 -0000 1.2 @@ -1,4 +1,3 @@ -#region using using System; using System.Collections.Generic; using System.Text; @@ -7,13 +6,13 @@ using System.Xml.Xsl; using System.Xml.XPath; using System.Diagnostics; -using System.Threading; -#endregion +using System.Threading; namespace Mvp.Xml.Common.Xsl { - public class XslReader : XmlReader { - static string NsXml = "http://www.w3.org/XML/1998/namespace"; - static int defaultBufferSize = 256; + class XslReader : XmlReader { + static string NsXml = "http://www.w3.org/XML/1998/namespace"; + static string NsXmlNs = "http://www.w3.org/2000/xmlns/"; + static int defaultBufferSize = 256; XmlNameTable nameTable; TokenPipe pipe; BufferWriter writer; @@ -217,11 +216,10 @@ if (attType != XmlNodeType.Attribute) { break; // We are done with attributes for this element } - if (attName == writer.QNameXmlLang) { - scope.AddLang(attText); - } else if (attName == writer.QNameXmlSpace) { - scope.AddSpace(attText); - } + if (RefEquals(attName.Prefix, "xmlns") ) { scope.AddNamespace(attName.Local , attText); } + else if (RefEquals(attName, writer.QNameXmlNs )) { scope.AddNamespace(attName.Prefix, attText); } // prefix is atomized empty string + else if (RefEquals(attName, writer.QNameXmlLang )) { scope.AddLang(attText); } + else if (RefEquals(attName, writer.QNameXmlSpace)) { scope.AddSpace(attText); } } scope.PushScope(qname); break; @@ -426,6 +424,22 @@ #endregion // XmlReader Implementation #region ------------------------------- Supporting classes ------------------------------ + private static bool RefEquals(string strA, string strB) { + Debug.Assert( + ((object)strA == (object)strB) || !String.Equals(strA, strB), + "String atomization Failure: '" + strA + "'" + ); + return (object)strA == (object)strB; + } + + private static bool RefEquals(QName qnA, QName qnB) { + Debug.Assert( + ((object)qnA == (object)qnB) || qnA.Local != qnB.Local || qnA.NsUri != qnB.NsUri || qnA.Prefix != qnB.Prefix, + "QName atomization Failure: '" + qnA.ToString() + "'" + ); + return (object)qnA == (object)qnB; + } + // QName is imutable. private class QName { string local; @@ -476,15 +490,16 @@ public QName QNameXmlSpace; public QName QNameXmlLang; public QName QNameEmpty; - + public QName QNameXmlNs; public BufferWriter(TokenPipe pipe, XmlNameTable nameTable) { this.pipe = pipe; this.qnameTable = new QNameTable(nameTable); this.sbuilder = new StringBuilder(); - QNameXmlSpace = qnameTable.GetQName("space", NsXml, "xml"); - QNameXmlLang = qnameTable.GetQName("lang" , NsXml, "xml"); - QNameEmpty = qnameTable.GetQName("", "", ""); + QNameXmlSpace = qnameTable.GetQName("space", NsXml , "xml" ); // xml:space + QNameXmlLang = qnameTable.GetQName("lang" , NsXml , "xml" ); // xml:lang + QNameXmlNs = qnameTable.GetQName("xmlns", NsXmlNs, "" ); // xmlsn="" + QNameEmpty = qnameTable.GetQName("" , "" , "" ); } public void Reset() { @@ -620,13 +635,6 @@ return s; } } - public static bool RefEquals(string strA, string strB) { - Debug.Assert( - ((object) strA == (object) strB) || ! String.Equals(strA, strB), - "Atomization Failure: '" + strA + "'" - ); - return (object) strA == (object) strB; - } } } @@ -676,9 +684,9 @@ if (record.Local != null) { break; // this record is Element QName } - if ((object) record.Prefix == (object) atomLang) { + if (RefEquals(record.Prefix, atomLang)) { currentLang = record.NsUri; - } else if ((object) record.Prefix == (object) atomSpace) { + } else if (RefEquals(record.Prefix, atomSpace)) { currentSpace = Str2Space(record.NsUri); } } while (true); @@ -696,11 +704,12 @@ public void AddNamespace(string prefix, string uri) { Debug.Assert(prefix != null); Debug.Assert(uri != null); - prefix = nameTable.Add(prefix); + Debug.Assert(prefix == nameTable.Add(prefix), "prefixes are expected to be already atomized in this NameTable"); uri = nameTable.Add(uri ); Debug.Assert( - (object)prefix != (object)atomLang && - (object)prefix != (object)atomSpace, + ! RefEquals(prefix, atomLang ) && + ! RefEquals(prefix, atomSpace) + , "This assumption is important to distinct NsDecl from xml:space and xml:lang" ); AddRecord(new QName(null, uri, prefix)); @@ -709,7 +718,7 @@ public void AddLang(string lang) { Debug.Assert(lang != null); lang = nameTable.Add(lang); - if ((object) lang == (object) currentLang) { + if (RefEquals(lang, currentLang)) { return; } AddRecord(new QName(null, currentLang, atomLang)); @@ -748,7 +757,7 @@ prefix = nameTable.Get(prefix); for (int i = lastRecord - 2; 0 <= i; i -- ) { QName record = records[i]; - if (record.Local == null && (object)record.Prefix == (object)prefix) { + if (record.Local == null && RefEquals(record.Prefix, prefix)) { return record.NsUri; } } |