本文整理汇总了C#中System.Xml.XmlTextWriter.WriteComment方法的典型用法代码示例。如果您正苦于以下问题:C# System.Xml.XmlTextWriter.WriteComment方法的具体用法?C# System.Xml.XmlTextWriter.WriteComment怎么用?C# System.Xml.XmlTextWriter.WriteComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlTextWriter
的用法示例。
在下文中一共展示了System.Xml.XmlTextWriter.WriteComment方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateEventSchemas
private void GenerateEventSchemas(UPnPDevice d, System.IO.DirectoryInfo dirInfo, bool cleanSchema)
{
System.IO.MemoryStream ms = new MemoryStream();
System.Xml.XmlTextWriter X = new System.Xml.XmlTextWriter(ms,System.Text.Encoding.UTF8);
X.Formatting = System.Xml.Formatting.Indented;
foreach(UPnPDevice ed in d.EmbeddedDevices)
{
GenerateEventSchemas(ed,dirInfo,cleanSchema);
}
foreach(UPnPService s in d.Services)
{
Hashtable h = new Hashtable();
int j=1;
foreach(string sn in s.GetSchemaNamespaces())
{
h[sn] = "CT"+j.ToString();
++j;
}
X.WriteStartDocument();
X.WriteStartElement("xsd","schema","http://www.w3.org/2001/XMLSchema");
X.WriteAttributeString("targetNamespace","urn:schemas-upnp-org:event-1-0");
X.WriteAttributeString("xmlns","upnp",null,"http://www.upnp.org/Schema/DataTypes");
X.WriteAttributeString("xmlns","urn:schemas-upnp-org:event-1-0");
foreach(UPnPStateVariable v in s.GetStateVariables())
{
if (v.SendEvent)
{
X.WriteStartElement("xsd","element",null); // Element1
X.WriteAttributeString("name","propertyset");
X.WriteAttributeString("type","propertysetType");
if (!cleanSchema)
{
X.WriteComment("Note: Some schema validation tools may consider the following xsd:any element to be ambiguous in its placement");
X.WriteStartElement("xsd","any",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("minOccurs","0");
X.WriteAttributeString("maxOccurs","unbounded");
X.WriteAttributeString("processContents","lax");
X.WriteEndElement(); //ANY
}
X.WriteStartElement("xsd","complexType",null);
X.WriteAttributeString("name","propertysetType");
X.WriteStartElement("xsd","sequence",null);
X.WriteStartElement("xsd","element",null); // Element2
X.WriteAttributeString("name","property");
X.WriteAttributeString("maxOccurs","unbounded");
X.WriteStartElement("xsd","complexType",null);
X.WriteStartElement("xsd","sequence",null);
X.WriteStartElement("xsd","element",null); // Element3
X.WriteAttributeString("name",v.Name);
if (v.ComplexType==null)
{
// Simple Type
X.WriteStartElement("xsd","complexType",null);
X.WriteStartElement("xsd","simpleContent",null);
X.WriteStartElement("xsd","extension",null);
X.WriteAttributeString("base","upnp:"+v.ValueType);
if (!cleanSchema)
{
X.WriteStartElement("xsd","anyAttribute",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("processContents","lax");
X.WriteEndElement(); // anyAttribute
}
X.WriteEndElement(); // extension
X.WriteEndElement(); // simpleContent
X.WriteEndElement(); // complexType
}
else
{
// Complex Type
X.WriteAttributeString("type",h[v.ComplexType.Name_NAMESPACE].ToString()+":"+v.ComplexType.Name_LOCAL);
}
X.WriteEndElement(); // Element3
if (!cleanSchema)
{
X.WriteStartElement("xsd","any",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("minOccurs","0");
X.WriteAttributeString("maxOccurs","unbounded");
X.WriteAttributeString("processContents","lax");
X.WriteEndElement(); // any
}
X.WriteEndElement(); // sequence
if (!cleanSchema)
{
X.WriteStartElement("xsd","anyAttribute",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("processContents","lax");
X.WriteEndElement(); // anyAttribute
}
X.WriteEndElement(); // complexType
X.WriteEndElement(); // Element2
//.........这里部分代码省略.........
示例2: GenerateControlSchemas
private void GenerateControlSchemas(UPnPDevice d, System.IO.DirectoryInfo dirInfo, bool cleanSchema)
{
System.IO.MemoryStream ms = new MemoryStream();
System.Xml.XmlTextWriter X = new System.Xml.XmlTextWriter(ms,System.Text.Encoding.UTF8);
X.Formatting = System.Xml.Formatting.Indented;
foreach(UPnPDevice ed in d.EmbeddedDevices)
{
GenerateControlSchemas(ed,dirInfo,cleanSchema);
}
foreach(UPnPService s in d.Services)
{
Hashtable h = new Hashtable();
int j=1;
foreach(string sn in s.GetSchemaNamespaces())
{
h[sn] = "CT"+j.ToString();
++j;
}
X.WriteStartDocument();
X.WriteStartElement("xsd","schema","http://www.w3.org/2001/XMLSchema");
X.WriteAttributeString("targetNamespace",s.ServiceURN);
X.WriteAttributeString("xmlns",s.ServiceURN);
X.WriteAttributeString("xmlns","upnp",null,"http://www.upnp.org/Schema/DataTypes");
IDictionaryEnumerator NE = h.GetEnumerator();
while(NE.MoveNext())
{
X.WriteAttributeString("xmlns",NE.Value.ToString(),null,NE.Key.ToString());
}
foreach(UPnPAction a in s.Actions)
{
X.WriteStartElement("xsd","element",null);
X.WriteAttributeString("name",a.Name);
X.WriteAttributeString("type",a.Name+"Type");
X.WriteEndElement();
X.WriteStartElement("xsd","element",null);
X.WriteAttributeString("name",a.Name+"Response");
X.WriteAttributeString("type",a.Name+"ResponseType");
X.WriteEndElement();
if (!cleanSchema)
{
X.WriteComment("Note: Some schema validation tools may consider the following xsd:any element ambiguous in this placement");
X.WriteStartElement("xsd","any",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("minOccurs","0");
X.WriteAttributeString("maxOccurs","unbounded");
X.WriteAttributeString("processContents","lax");
X.WriteEndElement(); // ANY
}
X.WriteStartElement("xsd","complexType",null);
X.WriteAttributeString("name",a.Name+"Type");
X.WriteStartElement("xsd","sequence",null);
foreach(UPnPArgument arg in a.Arguments)
{
if (arg.Direction=="in")
{
X.WriteStartElement("xsd","element",null);
X.WriteAttributeString("name",arg.Name);
if (arg.RelatedStateVar.ComplexType==null)
{
// Simple Types
X.WriteStartElement("xsd","complexType",null);
X.WriteStartElement("xsd","simpleContent",null);
X.WriteStartElement("xsd","extension",null);
X.WriteAttributeString("base","upnp:"+arg.RelatedStateVar.ValueType);
if (!cleanSchema)
{
X.WriteStartElement("xsd","anyAttribute",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("processContents","lax");
X.WriteEndElement(); // anyAttribute
}
X.WriteEndElement(); // Extension
X.WriteEndElement(); // simpleConent
X.WriteEndElement(); // complexType
}
else
{
// Complex Types
X.WriteAttributeString("type",h[arg.RelatedStateVar.ComplexType.Name_NAMESPACE].ToString()+":"+arg.RelatedStateVar.ComplexType.Name_LOCAL);
}
X.WriteEndElement(); // element
}
}
if (!cleanSchema)
{
X.WriteStartElement("xsd","any",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("minOccurs","0");
X.WriteAttributeString("maxOccurs","unbounded");
X.WriteAttributeString("processContents","lax");
//.........这里部分代码省略.........
示例3: Serialize
/// <summary> Writes the mapping of all mapped classes of the specified assembly in the specified stream. </summary>
/// <param name="stream">Where the xml is written.</param>
/// <param name="assembly">Assembly used to extract user-defined types containing a valid attribute (can be [Class] or [xSubclass]).</param>
public virtual void Serialize(System.IO.Stream stream, System.Reflection.Assembly assembly)
{
if(stream == null)
throw new System.ArgumentNullException("stream");
if(assembly == null)
throw new System.ArgumentNullException("assembly");
System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter( stream, System.Text.Encoding.UTF8 );
writer.Formatting = System.Xml.Formatting.Indented;
writer.WriteStartDocument();
if(WriteDateComment)
writer.WriteComment( string.Format( "Generated from NHibernate.Mapping.Attributes on {0}.", System.DateTime.Now.ToString("u") ) );
WriteHibernateMapping(writer, null);
// Write imports (classes decorated with the [ImportAttribute])
foreach(System.Type type in assembly.GetTypes())
{
object[] imports = type.GetCustomAttributes(typeof(ImportAttribute), false);
foreach(ImportAttribute import in imports)
{
writer.WriteStartElement("import");
if(import.Class != null && import.Class != string.Empty)
writer.WriteAttributeString("class", import.Class);
else // Assume that it is the current type that must be imported
writer.WriteAttributeString("class", HbmWriterHelper.GetNameWithAssembly(type));
if(import.Rename != null && import.Rename != string.Empty)
writer.WriteAttributeString("rename", import.Rename);
writer.WriteEndElement();
}
}
// Write classes and x-subclasses (classes must come first if inherited by "external" subclasses)
int classCount = 0;
System.Collections.ArrayList mappedClassesNames = new System.Collections.ArrayList();
foreach(System.Type type in assembly.GetTypes())
{
if( ! IsClass(type) )
continue;
HbmWriter.WriteClass(writer, type);
mappedClassesNames.Add(HbmWriterHelper.GetNameWithAssembly(type));
classCount++;
}
System.Collections.ArrayList subclasses = new System.Collections.ArrayList();
System.Collections.Specialized.StringCollection extendedClassesNames = new System.Collections.Specialized.StringCollection();
foreach(System.Type type in assembly.GetTypes())
{
if( ! IsSubclass(type) )
continue;
bool map = true;
System.Type t = type;
while( (t=t.DeclaringType) != null )
if (IsClass(t) || AreSameSubclass(type, t)) // If a base class is also mapped... (Note: A x-subclass can only contain x-subclasses of the same family)
{
map = false; // This class's mapping is already included in the mapping of the base class
break;
}
if(map)
{
subclasses.Add(type);
if( IsSubclass(type, typeof(SubclassAttribute)) )
extendedClassesNames.Add((type.GetCustomAttributes(typeof(SubclassAttribute), false)[0] as SubclassAttribute).Extends);
else if( IsSubclass(type, typeof(JoinedSubclassAttribute)) )
extendedClassesNames.Add((type.GetCustomAttributes(typeof(JoinedSubclassAttribute), false)[0] as JoinedSubclassAttribute).Extends);
else if( IsSubclass(type, typeof(UnionSubclassAttribute)) )
extendedClassesNames.Add((type.GetCustomAttributes(typeof(UnionSubclassAttribute), false)[0] as UnionSubclassAttribute).Extends);
}
}
classCount += subclasses.Count;
MapSubclasses(subclasses, extendedClassesNames, mappedClassesNames, writer);
writer.WriteEndElement(); // </hibernate-mapping>
writer.WriteEndDocument();
writer.Flush();
if(classCount == 0)
throw new MappingException("The following assembly contains no mapped classes: " + assembly.FullName);
if( ! Validate )
return;
// Validate the generated XML stream
try
{
writer.BaseStream.Position = 0;
System.Xml.XmlTextReader tr = new System.Xml.XmlTextReader(writer.BaseStream);
System.Xml.XmlValidatingReader vr = new System.Xml.XmlValidatingReader(tr);
// Open the Schema
System.IO.Stream schema = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("NHibernate.Mapping.Attributes.nhibernate-mapping.xsd");
vr.Schemas.Add("urn:nhibernate-mapping-2.2", new System.Xml.XmlTextReader(schema));
vr.ValidationType = System.Xml.ValidationType.Schema;
vr.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(XmlValidationHandler);
_stop = false;
while(vr.Read() && !_stop) // Read to validate (stop at the first error)
;
}
//.........这里部分代码省略.........
示例4: Convert
public void Convert(string SfmFileName, string MappingFileName, string OutputFileName,
string vernWs, string regWs, string natWs)
{
m_NumElements = 0;
// Log.Open(LogFileName);
if (!UseFiles(SfmFileName, MappingFileName, OutputFileName))
{
return;
}
using (System.Xml.XmlTextWriter xmlOutput = new System.Xml.XmlTextWriter(m_OutputFileName, System.Text.Encoding.UTF8))
{
xmlOutput.Formatting = System.Xml.Formatting.Indented;
xmlOutput.Indentation = 2;
WriteOutputFileComment(SfmFileName, MappingFileName, OutputFileName, xmlOutput);
xmlOutput.WriteComment(" database is the root element for this file ");
xmlOutput.WriteStartElement("database");
System.Xml.XmlDocument xmlMap = new System.Xml.XmlDocument();
try
{
xmlMap.Load(m_MappingFileName);
}
catch (System.Xml.XmlException e)
{
string ErrMsg = String.Format(Sfm2XmlStrings.InvalidMappingFile0_1, m_MappingFileName, e.Message);
Log.AddError(ErrMsg);
// put out the warnings and errors
Log.FlushTo(xmlOutput);
xmlOutput.WriteEndElement(); // Close the Database node
xmlOutput.Close();
return;
}
ReadLanguages(xmlMap);
// === Process the command line args relating to languages ===
// National ws
if (natWs.ToLowerInvariant() == STATICS.Ignore)
IgnoreWs("nat");
else if (natWs.ToLowerInvariant() == "no-convert")
NoConvertWs("nat");
else if (natWs.Length > 0)
ConvertWs("nat", natWs);
// Regional ws
if (regWs.ToLowerInvariant() == STATICS.Ignore)
IgnoreWs("reg");
else if (regWs.ToLowerInvariant() == "no-convert")
NoConvertWs("reg");
else if (regWs.Length > 0)
ConvertWs("reg", regWs);
// Vern ws
// if (vernWs.ToLowerInvariant() == "ignore")
// IgnoreWs("vern");
if (vernWs.ToLowerInvariant() == "no-convert")
NoConvertWs("vern");
else if (vernWs.Length > 0)
ConvertWs("vern", vernWs);
try
{
ReadHierarchy(xmlMap);
ReadAndOutputSettings(xmlMap, xmlOutput);
// read the mapping file and build internal classes / objects and
// add field descriptions to output file
ReadFieldDescriptions(xmlMap); // ReadAndOutputFieldDescriptions(xmlMap, xmlOutput);
ReadCustomFieldDescriptions(xmlMap);
// read the mapping file inline markers
ReadInFieldMarkers(xmlMap);
// Now vaildate the data read in. This must be done in the follwoing order:
// Languages, Field Descriptions, Hierarchy. Infield Markers must be validated
// after Languages. This order is needed because the later checks rely on
// success of the earlier ones.
ValidateLanguages(); // throw if bad language data
ValidateFieldDescriptions();
ValidateCustomFieldDescriptions();
ValidateHierarchy();
ValidateInfieldMarkers();
}
catch (System.Exception e)
{
string ErrMsg = String.Format(Sfm2XmlStrings.UnhandledException0, e.Message);
Log.AddError(ErrMsg);
}
string nl = System.Environment.NewLine;
string comments = nl;
comments += " ================================================================" + nl;
comments += " Element: " + m_Root.Name + nl;
comments += " This element contains the inputfile in an XML format." + nl;
comments += " ================================================================" + nl;
xmlOutput.WriteComment(comments);
// xmlOutput.WriteComment(" This element contains the inputfile in an XML format ");
//.........这里部分代码省略.........