本文整理匯總了C#中System.Xml.XmlParserContext類的典型用法代碼示例。如果您正苦於以下問題:C# XmlParserContext類的具體用法?C# XmlParserContext怎麽用?C# XmlParserContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
XmlParserContext類屬於System.Xml命名空間,在下文中一共展示了XmlParserContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Constructor2
public void Constructor2 ()
{
XmlDocument doc = new XmlDocument ();
XmlNamespaceManager ns = new XmlNamespaceManager (doc.NameTable);
XmlParserContext pc = new XmlParserContext (doc.NameTable,
ns, "dunno", XmlSpace.None, Encoding.UTF8);
Assert.AreEqual (string.Empty, pc.BaseURI, "#A1");
Assert.AreEqual (string.Empty, pc.DocTypeName, "#A2");
Assert.AreEqual (Encoding.UTF8, pc.Encoding, "#A3");
Assert.AreEqual (string.Empty, pc.InternalSubset, "#A4");
Assert.AreSame (ns, pc.NamespaceManager, "#A5");
Assert.AreSame (doc.NameTable, pc.NameTable, "#A6");
Assert.AreEqual (string.Empty, pc.PublicId, "#A7");
Assert.AreEqual (string.Empty, pc.SystemId, "#A8");
Assert.AreEqual ("dunno", pc.XmlLang, "#A9");
Assert.AreEqual (XmlSpace.None, pc.XmlSpace, "#A10");
pc = new XmlParserContext ((NameTable) null, (XmlNamespaceManager) null,
(string) null, XmlSpace.None, (Encoding) null);
Assert.AreEqual (string.Empty, pc.BaseURI, "#B1");
Assert.AreEqual (string.Empty, pc.DocTypeName, "#B2");
Assert.IsNull (pc.Encoding, "#B3");
Assert.AreEqual (string.Empty, pc.InternalSubset, "#B4");
Assert.IsNull (pc.NamespaceManager, "#B5");
Assert.IsNull (pc.NameTable, "#B6");
Assert.AreEqual (string.Empty, pc.PublicId, "#B7");
Assert.AreEqual (string.Empty, pc.SystemId, "#B8");
Assert.AreEqual (string.Empty, pc.XmlLang, "#B9");
Assert.AreEqual (XmlSpace.None, pc.XmlSpace, "#B10");
}
示例2: ExtractQuery
public static string ExtractQuery(string fileName, TextWriter errorlogger)
{
try
{
string data = File.ReadAllText(fileName);
XmlParserContext context = new XmlParserContext(null, null, null, XmlSpace.None);
Stream xmlFragment = new MemoryStream(Encoding.UTF8.GetBytes(data));
XmlTextReader reader = new XmlTextReader(xmlFragment, XmlNodeType.Element, context);
reader.MoveToContent();
if (reader.NodeType == XmlNodeType.Text)
{
return data;
}
XmlReader reader2 = reader.ReadSubtree();
StringBuilder output = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(output))
{
writer.WriteNode(reader2, true);
}
StringReader reader3 = new StringReader(data);
for (int i = 0; i < reader.LineNumber; i++)
{
reader3.ReadLine();
}
return reader3.ReadToEnd().Trim();
}
catch (Exception ex)
{
errorlogger.WriteLine(ex.Message);
errorlogger.WriteLine(ex.StackTrace);
}
return string.Format("//Error loading the file - {0} .The the linq file might be a linqpad expression which is not supported in the viewer currently." ,fileName);
}
示例3: GetIssueListFromXmlStream
public static List<Issue> GetIssueListFromXmlStream(Stream stream) {
List<Issue> issues = new List<Issue>();
XmlTextReader reader = new XmlTextReader(stream);
XmlDocument doc = new XmlDocument();
doc.Load(reader);
reader.Close();
XmlNodeList list = doc.DocumentElement.GetElementsByTagName("item");
XmlSerializer s = new XmlSerializer(typeof(Issue));
//Create the XmlNamespaceManager.
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("jc", "urn:jiraconn");
//Create the XmlParserContext.
XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
foreach (XmlNode item in list)
{
//Create the reader.
XmlTextReader itemReader = new XmlTextReader(item.OuterXml, XmlNodeType.Element, context);
Issue issue = (Issue)s.Deserialize(itemReader);
issues.Add(issue);
}
return issues;
}
示例4: RenderComponentFieldAsBBCode
public string RenderComponentFieldAsBBCode(string fieldExpression, int fieldIndex, bool outputImages)
{
BuiltInFunctions functions = new BuiltInFunctions(_engine, _package);
string output = functions.RenderComponentField(fieldExpression, fieldIndex);
StringReader sr = new StringReader(output);
NameTable nt = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("tcdl", Tridion.ContentManager.Templating.TcdlTags.TcdlNamespace);
XmlParserContext parserContext = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
XmlReader xmlReader = XmlReader.Create(sr, new XmlReaderSettings(), parserContext);
XslCompiledTransform transform = new XslCompiledTransform(true);
using (Stream xsltStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Tridion.ContentManager.Templating.Expression.NetbiscuitsFunctions.XhtmlToBBCode.xslt"))
{
using (XmlReader xsltReader = XmlReader.Create(xsltStream))
{
transform.Load(xsltReader);
}
}
StringWriter resultWriter = new StringWriter();
XsltArgumentList argumentList = new XsltArgumentList();
argumentList.AddParam("IncludeImages", String.Empty, outputImages);
transform.Transform(xmlReader, argumentList, resultWriter);
return resultWriter.ToString();
}
示例5: Validate
/// <summary>
/// Validates XML definition against given XSD schema.
/// </summary>
/// <param name="xmlFileName">Full path to the XML file on file system.</param>
/// <param name="schemaContent">XSD schema.</param>
/// <param name="schemaName">XSD schema name.</param>
public void Validate(string xmlFileName, string schemaContent, string schemaName)
{
_xmlFileName = xmlFileName;
var xmlDoc = GetUpdatedXml(xmlFileName, schemaName);
var xmlSchemaSet = GetXmlSchema(schemaContent, schemaName);
var nt = new NameTable();
var nsmgr = new XmlNamespaceManager(nt);
var context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
var settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(xmlSchemaSet);
settings.ValidationEventHandler += ValidationCallbackOne;
using (var xmlr = new XmlTextReader(xmlDoc.OuterXml, XmlNodeType.Document, context))
{
using (var reader = XmlReader.Create(xmlr, settings))
{
while (reader.Read())
{
var val = reader.Value;
}
}
}
}
示例6: nodeSet
/// <summary>
/// Implements the following function
/// node-set exsl:node-set(object)
/// </summary>
/// <param name="o"></param>
/// <returns></returns>
public XPathNodeIterator nodeSet(object o)
{
if (o is XPathNavigator)
{
XPathNavigator nav = (XPathNavigator)o;
if (selectItself == null)
selectItself = nav.Compile(".");
return nav.Select(selectItself.Clone());
}
else if (o is XPathNodeIterator)
return o as XPathNodeIterator;
else
{
string s;
if (o is string)
s = o as string;
else if (o is bool)
s = ((bool)o)? "true" : "false";
else if (o is Double || o is Int16 || o is UInt16 || o is Int32
|| o is UInt32 || o is Int64 || o is UInt64 || o is Single || o is Decimal)
s = o.ToString();
else
return null;
//Now convert it to text node
XmlParserContext context = new XmlParserContext(null, null, null, XmlSpace.None);
XPathDocument doc = new XPathDocument(
new XmlTextReader("<d>"+s+"</d>", XmlNodeType.Element, context));
XPathNavigator nav = doc.CreateNavigator();
if (selectText == null)
selectText = nav.Compile("/d/text()");
return nav.Select(selectText.Clone());
}
}
示例7: ParseIATIXML
/// <summary>
/// Implements ParseXML
/// </summary>
/// <returns></returns>
public IXmlResult ParseIATIXML(string url)
{
IXmlResult xmlResult;
var serializer = new XmlSerializer(typeof(XmlResultv1), new XmlRootAttribute("result"));
// Create an XmlNamespaceManager to resolve namespaces.
NameTable nameTable = new NameTable();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nameTable);
nsmgr.AddNamespace("iati-extra", "");
// Create an XmlParserContext. The XmlParserContext contains all the information
// required to parse the XML fragment, including the entity information and the
// XmlNamespaceManager to use for namespace resolution.
XmlParserContext xmlParserContext = new XmlParserContext(nameTable, nsmgr, null, XmlSpace.None);
// Create the reader.
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.NameTable = nameTable;
using (var Reader = XmlReader.Create(url, xmlReaderSettings, xmlParserContext))
{
xmlResult = (XmlResultv1)serializer.Deserialize(Reader);
}
return xmlResult;
}
示例8: ImportAuthors
public static List<WPAuthor> ImportAuthors(string fileLocation)
{
try
{
var nsm = new XmlNamespaceManager(new NameTable());
nsm.AddNamespace("wp", "http://wordpress.org/export/1.2/excerpt/");
var parseContext = new XmlParserContext(null, nsm, null, XmlSpace.Default);
using (var reader = XmlReader.Create(fileLocation, null, parseContext))
{
var doc = XDocument.Load(reader);
string WordpressNamespace = "http://wordpress.org/export/1.2/";
XNamespace wpContent = WordpressNamespace;
List<WPAuthor> blogAuthors = new List<WPAuthor>();
foreach (XElement element in doc.Descendants("channel"))
{
foreach (XElement e in element.Descendants(wpContent + "author"))
{
WPAuthor auth = new WPAuthor(e);
blogAuthors.Add(auth);
}
}
return blogAuthors;
}
}
catch (Exception ex)
{
Log.Error("Failed to import authors: " + ex.Message, "WP Importer");
return new List<WPAuthor>();
}
}
示例9: XmlValidatingReader
public XmlValidatingReader( Stream xmlFragment, XmlNodeType fragType, XmlParserContext context ) {
if (xmlFragment == null) {
throw new ArgumentNullException("xmlFragment");
}
impl = new XmlValidatingReaderImpl(xmlFragment, fragType, context);
impl.OuterReader = this;
}
示例10: Build
/// <summary>
/// Constructs an <see cref="IContainerProfile"/>
/// from a XML fragment.
/// </summary>
/// <param name="xmlContents"></param>
/// <returns></returns>
public virtual IContainerProfile Build(String xmlContents)
{
XmlNamespaceManager nsManager = new XmlNamespaceManager(new NameTable());
XmlParserContext context = new XmlParserContext(null, nsManager, null, XmlSpace.None);
XmlReader reader = new XmlTextReader(xmlContents, XmlNodeType.Element, context);
return Build(reader);
}
示例11: XmlValidatingReader
public XmlValidatingReader(String xmlFragment, XmlNodeType fragType,
XmlParserContext context)
{
reader = new XmlTextReader(xmlFragment, fragType, context);
entityHandling = EntityHandling.ExpandEntities;
validationType = ValidationType.Auto;
reader.Normalization = true;
}
示例12: Main
static void Main(string[] args)
{
try
{
//XML fragment para validar
string xmlFrag =
@"<address myns:Pais='port' myns:PaisCode='351' xmlns='http://SD/PTAddress.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >" +
"<nome>ISEL</nome>" +
"<rua>Conselheiro Emidio Navarro</rua>" +
"<numero>1</numero>" + "<!-- comentario -->" +
"<numero>2</numero>" +
"<numero>3</numero>" +
"<numero>4</numero>" +
"<cidade>Lisboa</cidade>" +
"<codigo-postal>1950</codigo-postal>" +
"</address>";
//Set the settings to xml reader and add the schema
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add("http://SD/PTAddress.xsd", "..\\..\\XMLSchemaPTAddress.xsd");
settings.ValidationType = ValidationType.Schema;
settings.ValidationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.ValidationEventHandler += new ValidationEventHandler(ShowParserErrors);
// Create the XmlNamespaceManager.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("myns", "http://SD/PTAddress.xsd");
// Create the XmlParserContext.
XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
XmlReader reader = XmlReader.Create(new StringReader(xmlFrag), settings, context);
while (reader.Read())
{
//ler toda a string com fragmento xml
}
if (!erro) Console.WriteLine("XML fragment VÁLIDO");
}
catch (XmlException XmlExp)
{
Console.WriteLine(XmlExp.Message);
}
catch (XmlSchemaException XmlSchExp)
{
Console.WriteLine(XmlSchExp.Message);
}
catch (Exception GenExp)
{
Console.WriteLine(GenExp.Message);
}
finally
{
Console.Read();
}
}
示例13: EntityResolvingXmlReader
public EntityResolvingXmlReader (XmlReader source)
{
this.source = source;
IHasXmlParserContext container = source as IHasXmlParserContext;
if (container != null)
this.context = container.ParserContext;
else
this.context = new XmlParserContext (source.NameTable, new XmlNamespaceManager (source.NameTable), null, XmlSpace.None);
}
示例14: Parse1
public void Parse1 ()
{
XmlNamespaceManager nsMgr = new MyNS (XmlReader.Create (new StringReader (empty)));
nsMgr.AddNamespace ("foo", "bar");
XmlParserContext inputContext = new XmlParserContext (null, nsMgr, null, XmlSpace.None);
XmlReader xr = XmlReader.Create (new StringReader (xmlstr), new XmlReaderSettings (), inputContext);
while (xr.Read ()) {}
}
示例15: XmlValidatingReader
public XmlValidatingReader(string xmlFragment, XmlNodeType fragType, XmlParserContext context)
{
if (xmlFragment == null)
{
throw new ArgumentNullException(nameof(xmlFragment));
}
_impl = new XmlValidatingReaderImpl(xmlFragment, fragType, context);
_impl.OuterReader = this;
}