本文整理汇总了C#中System.Xml.Serialization.XmlSerializerNamespaces.Add方法的典型用法代码示例。如果您正苦于以下问题:C# XmlSerializerNamespaces.Add方法的具体用法?C# XmlSerializerNamespaces.Add怎么用?C# XmlSerializerNamespaces.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Serialization.XmlSerializerNamespaces
的用法示例。
在下文中一共展示了XmlSerializerNamespaces.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getRequestContent
public byte[] getRequestContent( string doctype, string root, Type type, object obj)
{
XmlSerializer serializer = null;
if (root == null)
{
//... root element will be the object type name
serializer = new XmlSerializer(type);
}
else
{
//... root element set explicitely
var xattribs = new XmlAttributes();
var xroot = new XmlRootAttribute(root);
xattribs.XmlRoot = xroot;
var xoverrides = new XmlAttributeOverrides();
xoverrides.Add(type, xattribs);
serializer = new XmlSerializer(type, xoverrides);
}
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = false;
settings.OmitXmlDeclaration = false;
settings.Encoding = new UTF8Encoding(false/*no BOM*/, true/*throw if input illegal*/);
XmlSerializerNamespaces xmlNameSpace = new XmlSerializerNamespaces();
xmlNameSpace.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
xmlNameSpace.Add("noNamespaceSchemaLocation", m_schemadir + "/" + doctype + "." + m_schemaext);
StringWriter sw = new StringWriter();
XmlWriter xw = XmlWriter.Create( sw, settings);
xw.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
serializer.Serialize(xw, obj, xmlNameSpace);
return settings.Encoding.GetBytes( sw.ToString());
}
示例2: Cancelar
public string Cancelar()
{
try
{
XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();
nameSpaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
nameSpaces.Add("tipos", "http://localhost:8080/WsNFe2/tp");
nameSpaces.Add("ns1", "http://localhost:8080/WsNFe2/lote");
string sPath = Pastas.PROTOCOLOS + "\\REQ_CANC_LOTE_" + objCancelamento.lote.Id.Replace("Lote:", "") + ".xml";
if (File.Exists(sPath))
{
File.Delete(sPath);
}
string sXmlSerializer = null;
XmlSerializer xs = new XmlSerializer(typeof(ReqCancelamentoNFSe));
MemoryStream memory = new MemoryStream();
XmlTextWriter xmltext = new XmlTextWriter(memory, Encoding.UTF8);
xs.Serialize(xmltext, objCancelamento, nameSpaces);
UTF8Encoding encoding = new UTF8Encoding();
sXmlSerializer = encoding.GetString(memory.ToArray());
sXmlSerializer = sXmlSerializer.Substring(1);
belAssinaXml Assinatura = new belAssinaXml();
sXmlSerializer = Assinatura.ConfigurarArquivo(sXmlSerializer, "Lote", Acesso.cert_NFs);
//SerializeClassToXml.SerializeClasse<ReqCancelamentoNFSe>(objCancelamento, sPath, nameSpaces);
XmlDocument xmlConsulta = new XmlDocument();
xmlConsulta.LoadXml(sXmlSerializer);
xmlConsulta.Save(sPath);
belValidaXml.ValidarXml("http://localhost:8080/WsNFe2/lote", Pastas.SCHEMA_NFSE_DSF + "\\ReqCancelamentoNFSe.xsd", sPath);
string sPathRetConsultaCanc = Pastas.PROTOCOLOS + "\\Ret_CANC_LOTE_" + objCancelamento.lote.Id.Replace("Lote:", "") + ".xml";
HLP.GeraXml.WebService.NFSE_Campinas.LoteRpsService lt = new WebService.NFSE_Campinas.LoteRpsService();
string sRetornoLote = lt.cancelar(xmlConsulta.InnerXml);
xmlConsulta = new XmlDocument();
xmlConsulta.LoadXml(sRetornoLote);
xmlConsulta.Save(sPathRetConsultaCanc);
// sPathRetConsultaCanc = @"D:\Ret_CANC_LOTE_2805131157.xml";
RetornoCancelamentoNFSe objretorno = SerializeClassToXml.DeserializeClasse<RetornoCancelamentoNFSe>(sPathRetConsultaCanc);
string sMessageRetorno = TrataRetornoCancelamento(objretorno);
return sMessageRetorno;
}
catch (Exception ex)
{
throw ex;
}
}
示例3: Parse
/// <summary>
/// Parses the export file at the specified disk path.
/// </summary>
/// <param name="diskPathToExportFile">The disk path to the export file.</param>
public Feed Parse(string diskPathToExportFile)
{
diskPathToExportFile.CheckNullOrEmpty("diskPathToExportFile");
Log.InfoFormat("blogger2jekyll.Blogger.ExportXmlParses conversion started at {0}.", DateTime.Now);
Log.InfoFormat("Using Blogger import file at {0}", diskPathToExportFile);
XmlDocument sourceDocument = new XmlDocument();
sourceDocument.Load(diskPathToExportFile);
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add(string.Empty, string.Empty);
ns.Add("app", "http://purl.org/atom/app#");
XmlSerializer serializer = new XmlSerializer(typeof(Feed));
Feed feed = (Feed)serializer.Deserialize(new StringReader(sourceDocument.OuterXml));
ProcessComments(feed);
ProcessPages(feed);
ProcessSettings(feed);
Log.InfoFormat("blogger2jekyll.Blogger.ExportXmlParses conversion completed at {0}.", DateTime.Now);
Log.InfoFormat("The blog {0} was converted.", feed.Title);
Log.InfoFormat("{0} posts were found in the export file.", feed.Posts.Count);
return feed;
}
示例4: ToXML
public XmlDocument ToXML()
{
using (MemoryStream stream = new MemoryStream())
{
// xmlns:georss="http://www.georss.org/georss"
// xmlns:gml="http://www.opengis.net/gml"
//xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
//xmlns:kml="http://www.opengis.net/kml/2.2"
//xmlns:dc="http://purl.org/dc/elements/1.1/"
var ns = new XmlSerializerNamespaces();
ns.Add("georss", "http://www.georss.org/georss");
ns.Add("gml", "http://www.opengis.net/gml");
ns.Add("geo", "http://www.w3.org/2003/01/geo/wgs84_pos#");
ns.Add("kml", "http://www.opengis.net/kml/2.2");
ns.Add("dc", "http://purl.org/dc/elements/1.1/");
XmlSerializer s = new XmlSerializer(this.GetType());
Console.WriteLine("Testing for type: {0}", this.GetType());
s.Serialize(XmlWriter.Create(stream), this, ns);
stream.Flush();
stream.Seek(0, SeekOrigin.Begin);
//object o = s.Deserialize(XmlReader.Create(stream));
//Console.WriteLine(" Deserialized type: {0}", o.GetType());
XmlDocument xml = new XmlDocument();
xml.Load(stream);
Console.Write(xml.InnerXml);
return xml;
}
//var serializer = new XmlSerializer(this.GetType());
//serializer.Serialize(new StreamWriter("test.xml"), this);
}
示例5: WriteObject
public bool WriteObject(XPathResult result, XPathNavigator node, object value)
{
var rootOverride = new XmlRootAttribute(node.LocalName)
{
Namespace = node.NamespaceURI
};
var xml = new StringBuilder();
var settings = new XmlWriterSettings
{
OmitXmlDeclaration = true,
Indent = false
};
var namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);
if (string.IsNullOrEmpty(node.NamespaceURI) == false)
{
var prefix = result.Context.AddNamespace(node.NamespaceURI);
namespaces.Add(prefix, node.NamespaceURI);
}
var serializer = new XmlSerializer(result.Type, rootOverride);
using (var writer = XmlWriter.Create(xml, settings))
{
serializer.Serialize(writer, value, namespaces);
writer.Flush();
}
node.ReplaceSelf(xml.ToString());
return true;
}
示例6: Write
public void Write(Stream outputStream, object artifact)
{
using (var stream = new MemoryStream())
{
var serializer = new XmlSerializer(artifact.GetType(), "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
var ns = new XmlSerializerNamespaces();
ns.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
ns.Add("ds", "http://schemas.allscripts.com/cds/evaluation");
ns.Add("am", "http://schemas.allscripts.com/mom");
serializer.Serialize(stream, artifact, ns);
// This seems like a bug with the serializer to me, but the outer-most instance of
// Composite expression within the artifact is serialized with the prefix ds, instead
// of am, even though the CompositeAssertion class has the XmlNamespaceAttribute with
// allscripts.com/mom as given above. So we serialize the output to a temporary stream,
// read it into a string, replace the offending instance with the correct value, and
// then write the output stream with that string.
stream.Position = 0;
using (var sr = new StreamReader(stream))
{
var result = sr.ReadToEnd();
using (var sw = new StreamWriter(outputStream))
{
sw.Write(result.Replace("ds:CompositeAssertion", "am:CompositeAssertion"));
}
}
}
}
示例7: SaveDelta
public static void SaveDelta(Delta delta, string file)
{
var ns = new XmlSerializerNamespaces();
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
ns.Add("xsd", "http://www.w3.org/2001/XMLSchema");
var serializer = new XmlSerializer(typeof(Delta));
var list = new List<ImportObject>();
foreach (var obj in delta.Objects.Where(x => x.NeedsInclude()))
{
var newObj = new ImportObject();
newObj.SourceObjectIdentifier = obj.SourceObjectIdentifier;
newObj.TargetObjectIdentifier = obj.TargetObjectIdentifier;
newObj.ObjectType = obj.ObjectType;
newObj.State = obj.State;
newObj.Changes = obj.Changes != null ? obj.Changes.Where(x => x.IsIncluded).ToArray() : null;
newObj.AnchorPairs = obj.AnchorPairs;
list.Add(newObj);
}
var newDelta = new Delta();
newDelta.Objects = list.ToArray();
var settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = false;
settings.Indent = true;
using (var w = XmlWriter.Create(file, settings))
serializer.Serialize(w, newDelta, ns);
}
示例8: UseCase
public UseCase()
{
Xmlns = new XmlSerializerNamespaces();
Xmlns.Add("ns3", ScenarioDocuXMLFileUtil.ScenarioNameSpace);
Xmlns.Add("xs", ScenarioDocuXMLFileUtil.XmlSchema);
Details = new Details();
}
示例9: Step
public Step()
{
ScreenAnnotations = new List<ScreenAnnotation>();
Xmlns = new XmlSerializerNamespaces();
Xmlns.Add("ns3", ScenarioDocuXMLFileUtil.ScenarioNameSpace);
Xmlns.Add("xs", ScenarioDocuXMLFileUtil.XmlSchema);
}
示例10: ReadRSS
public static Rss ReadRSS(Stream source)
{
XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
xsn.Add("atom", "http://www.w3.org/2005/Atom");
xsn.Add("dc", "http://purl.org/dc/elements/1.1/");
xsn.Add("content", "http://purl.org/rss/1.0/modules/content/");
XmlSerializer ser = new XmlSerializer(typeof(Rss));
return (Rss)ser.Deserialize(source);
}
示例11: SpreadsheetXmlSerializer
public SpreadsheetXmlSerializer()
{
_xmlSerializer = new XmlSerializer(typeof (Workbook), "urn:schemas-microsoft-com:office:spreadsheet");
_xmlNamespaces = new XmlSerializerNamespaces();
_xmlNamespaces.Add("ss", "urn:schemas-microsoft-com:office:spreadsheet");
_xmlNamespaces.Add("x", "urn:schemas-microsoft-com:office:excel");
_xmlNamespaces.Add("o", "urn:schemas-microsoft-com:office:office");
_xmlNamespaces.Add("c", "urn:schemas-microsoft-com:office:component:spreadsheet");
_xmlNamespaces.Add("html", "http://www.w3.org/TR/REC-html40");
}
示例12: ReadRss
public static Structure.RssFeed ReadRss(Stream source)
{
var xsn = new XmlSerializerNamespaces();
xsn.Add("atom", "http://www.w3.org/2005/Atom");
xsn.Add("dc", "http://purl.org/dc/elements/1.1/");
xsn.Add("content", "http://purl.org/rss/1.0/modules/content/");
var ser = new XmlSerializer(typeof(Structure.RssFeed));
return (Structure.RssFeed)ser.Deserialize(source);
}
示例13: WriteRss
public static void WriteRss(Structure.RssFeed value, Stream destination)
{
var xsn = new XmlSerializerNamespaces();
xsn.Add("atom", "http://www.w3.org/2005/Atom");
xsn.Add("dc", "http://purl.org/dc/elements/1.1/");
xsn.Add("content", "http://purl.org/rss/1.0/modules/content/");
var ser = new XmlSerializer(value.GetType());
ser.Serialize(destination, value, xsn);
}
示例14: Scenario
public Scenario()
{
Xmlns = new XmlSerializerNamespaces();
Xmlns.Add("ns3", ScenarioDocuXMLFileUtil.ScenarioNameSpace);
Xmlns.Add("xs", ScenarioDocuXMLFileUtil.XmlSchema);
Name = string.Empty;
Description = string.Empty;
Status = string.Empty;
Details = new Details();
}
示例15: Serialize
public static void Serialize(Manifest manifest, StreamWriter writer)
{
var xs = new XmlSerializer(typeof(Manifest));
var xsn = new XmlSerializerNamespaces();
xsn.Add(SCORM.Adlcp, SCORM.AdlcpNamespaceV1P3);
xsn.Add(SCORM.Imsss, SCORM.ImsssNamespace);
xsn.Add(SCORM.Adlseq, SCORM.AdlseqNamespace);
xsn.Add(SCORM.Adlnav, SCORM.AdlnavNamespace);
xsn.Add(SCORM.Imsss, SCORM.ImsssNamespace);
xs.Serialize(writer, manifest, xsn);
}