From: Daniel C. <kz...@gm...> - 2005-10-26 05:36:29
|
I was wondering whether those two hacky classes XmlFirstUpperReader and XmlFirstLowerWriter should be in a serious library.... looks like we could generalize these kinds of mini-transformation in a generic XmlTransformingReader and XmlTransformingWriter that can receive a delegate to the transforming code, in the two cases above, turning the first letter into upper/lower case... thoughts? On 10/25/05, mvp...@li... < mvp...@li...> wrote: > > Send mvp-xml-cvs mailing list submissions to > mvp...@li... > > To subscribe or unsubscribe via the World Wide Web, visit > https://lists.sourceforge.net/lists/listinfo/mvp-xml-cvs > or, via email, send a message with subject or body 'help' to > mvp...@li... > > You can reach the person managing the list at > mvp...@li... > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of mvp-xml-cvs digest..." > > > Today's Topics: > > 1. Common/v2/test/XmlFragments Tests.cs,NONE,1.1 publishers.xml,NONE,1.1(= Oleg Tkachenko) > 2. Common/v2/test/UpperLowerTests Customer.cs,NONE,1.1 Customer.xml,NONE, > 1.1 Customer.xsd,NONE,1.1 Customer.xsx,NONE,1.1 FirstUpperLowerTests.cs > ,NONE,1.1 (Oleg Tkachenko) > > --__--__-- > > Message: 1 > From: Oleg Tkachenko <he...@us...> > To: mvp...@li... > Date: Tue, 25 Oct 2005 21:33:46 +0000 > Subject: [mvp-xml-cvs] Common/v2/test/XmlFragments Tests.cs,NONE,1.1 > publishers.xml,NONE,1.1 > > Update of /cvsroot/mvp-xml/Common/v2/test/XmlFragments > In directory > sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1205/v2/test/XmlFragments > > Added Files: > Tests.cs publishers.xml > Log Message: > > > --- NEW FILE: publishers.xml --- > <publishers> > <pub_id>0736</pub_id> > <pub_name>New Moon Books</pub_name> > <city>Boston</city> > <state>MA</state> > <country>USA</country> > <titles> > <title_id>BU2075</title_id> > <title>You Can Combat Computer Stress!</title> > <type>business </type> > <pub_id>0736</pub_id> > <price>2.99</price> > <advance>10125</advance> > <royalty>24</royalty> > <ytd_sales>18722</ytd_sales> > <notes>The latest medical and psychological techniques for living with th= e > electronic office. Easy-to-understand explanations.</notes> > <pubdate>1991-06-30T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>PS2091</title_id> > <title>Is Anger the Enemy?</title> > <type>psychology </type> > <pub_id>0736</pub_id> > <price>10.95</price> > <advance>2275</advance> > <royalty>12</royalty> > <ytd_sales>2045</ytd_sales> > <notes>Carefully researched study of the effects of strong emotions on th= e > body. Metabolic charts included.</notes> > <pubdate>1991-06-15T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>PS2106</title_id> > <title>Life Without Fear</title> > <type>psychology </type> > <pub_id>0736</pub_id> > <price>7</price> > <advance>6000</advance> > <royalty>10</royalty> > <ytd_sales>111</ytd_sales> > <notes>New exercise, meditation, and nutritional techniques that can > reduce the shock of daily interactions. Popular audience. Sample menus > included, exercise video available separately.</notes> > <pubdate>1991-10-05T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>PS3333</title_id> > <title>Prolonged Data Deprivation: Four Case Studies</title> > <type>psychology </type> > <pub_id>0736</pub_id> > <price>19.99</price> > <advance>2000</advance> > <royalty>10</royalty> > <ytd_sales>4072</ytd_sales> > <notes>What happens when the data runs dry? Searching evaluations of > information-shortage effects.</notes> > <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>PS7777</title_id> > <title>Emotional Security: A New Algorithm</title> > <type>psychology </type> > <pub_id>0736</pub_id> > <price>7.99</price> > <advance>4000</advance> > <royalty>10</royalty> > <ytd_sales>3336</ytd_sales> > <notes>Protecting yourself and your loved ones from undue emotional stres= s > in the modern world. Use of computer and nutritional aids > emphasized.</notes> > <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> > </titles> > </publishers> > <publishers> > <pub_id>0877</pub_id> > <pub_name>Binnet & Hardley</pub_name> > <city>Washington</city> > <state>DC</state> > <country>USA</country> > <titles> > <title_id>MC2222</title_id> > <title>Silicon Valley Gastronomic Treats</title> > <type>mod_cook </type> > <pub_id>0877</pub_id> > <price>19.99</price> > <advance>0</advance> > <royalty>12</royalty> > <ytd_sales>2032</ytd_sales> > <notes>Favorite recipes for quick, easy, and elegant meals.</notes> > <pubdate>1991-06-09T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>MC3021</title_id> > <title>The Gourmet Microwave</title> > <type>mod_cook </type> > <pub_id>0877</pub_id> > <price>2.99</price> > <advance>15000</advance> > <royalty>24</royalty> > <ytd_sales>22246</ytd_sales> > <notes>Traditional French gourmet recipes adapted for modern microwave > cooking.</notes> > <pubdate>1991-06-18T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>MC3026</title_id> > <title>The Psychology of Computer Cooking</title> > <type>UNDECIDED </type> > <pub_id>0877</pub_id> > <pubdate>2000-08-06T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>PS1372</title_id> > <title>Computer Phobic AND Non-Phobic Individuals: Behavior > Variations</title> > <type>psychology </type> > <pub_id>0877</pub_id> > <price>21.59</price> > <advance>7000</advance> > <royalty>10</royalty> > <ytd_sales>375</ytd_sales> > <notes>A must for the specialist, this book examines the difference > between those who hate and fear computers and those who don't.</notes> > <pubdate>1991-10-21T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>TC3218</title_id> > <title>Onions, Leeks, and Garlic: Cooking Secrets of the > Mediterranean</title> > <type>trad_cook </type> > <pub_id>0877</pub_id> > <price>20.95</price> > <advance>7000</advance> > <royalty>10</royalty> > <ytd_sales>375</ytd_sales> > <notes>Profusely illustrated in color, this makes a wonderful gift book > for a cuisine-oriented friend.</notes> > <pubdate>1991-10-21T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>TC4203</title_id> > <title>Fifty Years in Buckingham Palace Kitchens</title> > <type>trad_cook </type> > <pub_id>0877</pub_id> > <price>11.95</price> > <advance>4000</advance> > <royalty>14</royalty> > <ytd_sales>15096</ytd_sales> > <notes>More anecdotes from the Queen's favorite cook describing life amon= g > English royalty. Recipes, techniques, tender vignettes.</notes> > <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>TC7777</title_id> > <title>Sushi, Anyone?</title> > <type>trad_cook </type> > <pub_id>0877</pub_id> > <price>14.99</price> > <advance>8000</advance> > <royalty>10</royalty> > <ytd_sales>4095</ytd_sales> > <notes>Detailed instructions on how to make authentic Japanese sushi in > your spare time.</notes> > <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> > </titles> > </publishers> > <publishers> > <pub_id>1389</pub_id> > <pub_name>Algodata Infosystems</pub_name> > <city>Berkeley</city> > <state>CA</state> > <country>USA</country> > <titles> > <title_id>BU1032</title_id> > <title>The Busy Executive's Database Guide</title> > <type>business </type> > <pub_id>1389</pub_id> > <price>19.99</price> > <advance>5000</advance> > <royalty>10</royalty> > <ytd_sales>4095</ytd_sales> > <notes>An overview of available database systems with emphasis on common > business applications. Illustrated.</notes> > <pubdate>1991-06-12T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>BU1111</title_id> > <title>Cooking with Computers: Surreptitious Balance Sheets</title> > <type>business </type> > <pub_id>1389</pub_id> > <price>11.95</price> > <advance>5000</advance> > <royalty>10</royalty> > <ytd_sales>3876</ytd_sales> > <notes>Helpful hints on how to use your electronic resources to the best > advantage.</notes> > <pubdate>1991-06-09T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>BU7832</title_id> > <title>Straight Talk About Computers</title> > <type>business </type> > <pub_id>1389</pub_id> > <price>19.99</price> > <advance>5000</advance> > <royalty>10</royalty> > <ytd_sales>4095</ytd_sales> > <notes>Annotated analysis of what computers can do for you: a no-hype > guide for the critical user.</notes> > <pubdate>1991-06-22T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>PC1035</title_id> > <title>But Is It User Friendly?</title> > <type>popular_comp</type> > <pub_id>1389</pub_id> > <price>22.95</price> > <advance>7000</advance> > <royalty>16</royalty> > <ytd_sales>8780</ytd_sales> > <notes>A survey of software for the naive user, focusing on the > 'friendliness' of each.</notes> > <pubdate>1991-06-30T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>PC8888</title_id> > <title>Secrets of Silicon Valley</title> > <type>popular_comp</type> > <pub_id>1389</pub_id> > <price>20</price> > <advance>8000</advance> > <royalty>10</royalty> > <ytd_sales>4095</ytd_sales> > <notes>Muckraking reporting on the world's largest computer hardware and > software manufacturers.</notes> > <pubdate>1994-06-12T00:00:00.0000000-03:00</pubdate> > </titles> > <titles> > <title_id>PC9999</title_id> > <title>Net Etiquette</title> > <type>popular_comp</type> > <pub_id>1389</pub_id> > <notes>A must-read for computer conferencing.</notes> > <pubdate>2000-08-06T00:00:00.0000000-03:00</pubdate> > </titles> > </publishers> > <publishers> > <pub_id>1622</pub_id> > <pub_name>Five Lakes Publishing</pub_name> > <city>Chicago</city> > <state>IL</state> > <country>USA</country> > </publishers> > <publishers> > <pub_id>1756</pub_id> > <pub_name>Ramona Publishers</pub_name> > <city>Dallas</city> > <state>TX</state> > <country>USA</country> > </publishers> > <publishers> > <pub_id>9901</pub_id> > <pub_name>GGG&G</pub_name> > <city>M=FCnchen</city> > <country>Germany</country> > </publishers> > <publishers> > <pub_id>9952</pub_id> > <pub_name>Scootney Books</pub_name> > <city>New York</city> > <state>NY</state> > <country>USA</country> > </publishers> > <publishers> > <pub_id>9999</pub_id> > <pub_name>Lucerne Publishing</pub_name> > <city>Paris</city> > <country>France</country> > </publishers> > --- NEW FILE: Tests.cs --- > using System; > using System.IO; > using System.Xml; > > using Mvp.Xml.Common; > using NUnit.Framework; > > namespace Mvp.Xml.Tests.XmlFragments > { > [TestFixture] > public class Tests > { > [Test] > public void ReadFragments() > { > XmlDocument doc =3D new XmlDocument(); > doc.Load(new XmlTextReader(null, new XmlFragmentStream(Globals.GetResourc= e > ( > this.GetType().Namespace + ".publishers.xml")))); > > doc =3D new XmlDocument(); > XmlNamespaceManager mgr =3D new XmlNamespaceManager(doc.NameTable); > XmlTextReader tr =3D new XmlTextReader(Globals.GetResource( > this.GetType().Namespace + ".publishers.xml"), XmlNodeType.Element, > new XmlParserContext( doc.NameTable, mgr, null, XmlSpace.None)); > while (tr.Read()) > { > Console.Write(doc.OuterXml); > } > } > > [Test] > public void ReadFragmentsRoot() > { > XmlDocument doc =3D new XmlDocument(); > doc.Load(new XmlTextReader(new XmlFragmentStream(Globals.GetResource( > this.GetType().Namespace + ".publishers.xml"), "pubs"))); > Console.Write(doc.OuterXml); > } > > [Test] > public void ReadFragmentsRootNs() > { > XmlDocument doc =3D new XmlDocument(); > doc.Load(new XmlTextReader(new XmlFragmentStream(Globals.GetResource( > this.GetType().Namespace + ".publishers.xml"), "pubs", "mvp-xml"))); > Console.Write(doc.OuterXml); > } > } > } > > > > --__--__-- > > Message: 2 > From: Oleg Tkachenko <he...@us...> > To: mvp...@li... > Date: Tue, 25 Oct 2005 21:33:46 +0000 > Subject: [mvp-xml-cvs] Common/v2/test/UpperLowerTests Customer.cs,NONE,1.= 1 > Customer.xml,NONE,1.1 Customer.xsd,NONE,1.1 Customer.xsx,NONE,1.1 > FirstUpperLowerTests.cs,NONE,1.1 > > Update of /cvsroot/mvp-xml/Common/v2/test/UpperLowerTests > In directory > sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1205/v2/test/UpperLowerTests > > Added Files: > Customer.cs Customer.xml Customer.xsd Customer.xsx > FirstUpperLowerTests.cs > Log Message: > > > --- NEW FILE: Customer.xml --- > (This appears to be a binary file; contents omitted.) > > --- NEW FILE: Customer.xsx --- > <?xml version=3D"1.0" encoding=3D"utf-8"?> > <!--This file is auto-generated by the XML Schema Designer. It holds > layout information for components on the designer surface.--> > <XSDDesignerLayout layoutVersion=3D"2" viewPortLeft=3D"0" viewPortTop=3D"= 0" > zoom=3D"100"> > <customer_XmlElement left=3D"317" top=3D"254" width=3D"5292" height=3D"29= 63" > selected=3D"0" zOrder=3D"1" index=3D"0" expanded=3D"1"> > <order_XmlElement left=3D"317" top=3D"3725" width=3D"5292" height=3D"2963= " > selected=3D"0" zOrder=3D"2" index=3D"1" expanded=3D"1" /> > </customer_XmlElement> > </XSDDesignerLayout> > --- NEW FILE: Customer.xsd --- > <?xml version=3D"1.0" encoding=3D"utf-8" ?> > <xs:schema id=3D"Customer" targetNamespace=3D"mvp-xml-customer" > elementFormDefault=3D"qualified" > xmlns=3D"mvp-xml-customer" xmlns:mstns=3D"mvp-xml-customer" xmlns:xs=3D" > http://www.w3.org/2001/XMLSchema"> > <xs:element name=3D"Customer"> > <xs:complexType> > <xs:sequence> > <xs:element name=3D"Name" type=3D"xs:string" /> > <xs:element name=3D"Order"> > <xs:complexType> > <xs:attribute name=3D"Id" type=3D"xs:int" use=3D"required" /> > </xs:complexType> > </xs:element> > </xs:sequence> > <xs:attribute name=3D"Id" type=3D"xs:string" /> > </xs:complexType> > </xs:element> > </xs:schema> > --- NEW FILE: Customer.cs --- > namespace Mvp.Xml.Tests.UpperLowerTests > { > > > /// <remarks/> > [System.Xml.Serialization.XmlTypeAttribute(Namespace=3D"mvp-xml-customer"= )] > [System.Xml.Serialization.XmlRootAttribute(Namespace=3D"mvp-xml-customer"= , > IsNullable=3Dfalse)] > public class Customer > { > > /// <remarks/> > public string Name; > > /// <remarks/> > public CustomerOrder Order; > > /// <remarks/> > [System.Xml.Serialization.XmlAttributeAttribute()] > public string Id; > } > > /// <remarks/> > [System.Xml.Serialization.XmlTypeAttribute(Namespace=3D"mvp-xml-customer"= )] > public class CustomerOrder > { > > /// <remarks/> > [System.Xml.Serialization.XmlAttributeAttribute()] > public int Id; > } > } > > --- NEW FILE: FirstUpperLowerTests.cs --- > #region using > > using System; > using System.Diagnostics; > using System.IO; > using System.Reflection; > using System.Xml; > using System.Xml.Serialization; > using System.Xml.XPath; > using System.Xml.Schema; > > using Mvp.Xml.Common; > using NUnit.Framework; > > #endregion using > > namespace Mvp.Xml.Tests.UpperLowerTests > { > [TestFixture] > public class FirstUpperLowerTests > { > [Test] > public void XmlFirstUpperReader() > { > string xml =3D "<customer id=3D'1' pp:id=3D'aba' xmlns=3D'urn-kzu' > xmlns:pp=3D'urn-pepenamespace'><pp:order /><order > id=3D'1'>Chocolates</order></customer>"; > > XmlFirstUpperReader fr =3D new XmlFirstUpperReader(new StringReader(xml))= ; > > fr.MoveToContent(); > Assert.AreEqual("Customer", fr.LocalName); > fr.MoveToFirstAttribute(); > Assert.AreEqual("Id", fr.LocalName); > fr.MoveToNextAttribute(); > Assert.AreEqual("pp:Id", fr.Name); > > // Namespace ordering is not guaranteed. > fr.MoveToNextAttribute(); > Assert.IsTrue( fr.Name =3D=3D "xmlns" || fr.Name =3D=3D "xmlns:pp" ); > fr.MoveToNextAttribute(); > Assert.IsTrue( fr.Name =3D=3D "xmlns" || fr.Name =3D=3D "xmlns:pp" ); > > fr.MoveToElement(); > fr.Read(); > Assert.AreEqual("pp:Order", fr.Name); > } > > [Test] > public void XmlFirstLowerWriter() > { > string xml =3D "<Customer Id=3D\"1\" pp:Id=3D\"aba\" xmlns=3D\"urn-kzu\" > xmlns:pp=3D\"urn-pepenamespace\"><pp:Order /><Order > Id=3D\"1\">chocolates</Order></Customer>"; > > XmlTextReader tr =3D new XmlTextReader(new StringReader(xml)); > > StringWriter sw =3D new StringWriter(); > XmlFirstLowerWriter fw =3D new XmlFirstLowerWriter(sw); > > fw.WriteNode(tr, true); > fw.Flush(); > > Assert.AreEqual(xml.ToLower(), sw.ToString()); > } > > [Test] > public void Deserialization() > { > XmlFirstUpperReader fu =3D new XmlFirstUpperReader(Globals.GetResource( > this.GetType().Namespace + ".Customer.xml")); > XmlReaderSettings settings =3D new XmlReaderSettings(); > settings.ValidationType =3D ValidationType.Schema; > settings.Schemas.Add(XmlSchema.Read(Globals.GetResource( > this.GetType().Namespace + ".Customer.xsd"), null)); > XmlReader vr =3D XmlReader.Create(fu, settings); > XmlSerializer ser =3D new XmlSerializer(typeof(Customer)); > Customer c =3D (Customer) ser.Deserialize(vr); > > Assert.AreEqual("0736", c.Id); > Assert.AreEqual("Daniel Cazzulino", c.Name); > Assert.AreEqual(25, c.Order.Id <http://c.Order.Id>); > } > > [Test] > public void Serialization() > { > XmlFirstUpperReader fu =3D new XmlFirstUpperReader(Globals.GetResource( > this.GetType().Namespace + ".Customer.xml")); > XmlSerializer ser =3D new XmlSerializer(typeof(Customer)); > Customer c =3D (Customer) ser.Deserialize(fu); > > StringWriter sw =3D new StringWriter(); > XmlFirstLowerWriter fl =3D new XmlFirstLowerWriter(sw); > > ser.Serialize(fl, c); > > Assert.AreEqual("<?xml version=3D\"1.0\" encoding=3D\"utf-16\"?><customer > xmlns:xsd=3D\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=3D\" > http://www.w3.org/2001/XMLSchema-instance\" id=3D\"0736\" > xmlns=3D\"mvp-xml-customer\"><name>Daniel Cazzulino</name><order id=3D\"2= 5\" > /></customer>", > sw.ToString()); > } > } > } > > > > --__--__-- > > _______________________________________________ > mvp-xml-cvs mailing list > mvp...@li... > https://lists.sourceforge.net/lists/listinfo/mvp-xml-cvs > > > End of mvp-xml-cvs Digest > > -- Daniel Cazzulino [MVP XML] Clarius Consulting SA http://clariusconsulting.net/kzu "He who is good for making excuses, is seldom good for anything else." |