本文整理汇总了C#中System.IO.XmlReader.ResolveEntity方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.ResolveEntity方法的具体用法?C# XmlReader.ResolveEntity怎么用?C# XmlReader.ResolveEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.XmlReader
的用法示例。
在下文中一共展示了XmlReader.ResolveEntity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildSubtree
internal static void BuildSubtree(XmlReader reader, XmlWriter writer)
{
// important (perf) string literal...
string xmlnsUri = XmlConst.ReservedNsXmlNs; // http://www.w3.org/2000/xmlns/
ReadState readState = reader.ReadState;
if (readState != ReadState.Initial
&& readState != ReadState.Interactive)
{
throw new ArgumentException(SR.Xml_InvalidOperation, "reader");
}
int level = 0;
if (readState == ReadState.Initial)
{
if (!reader.Read())
return;
level++; // if start in initial, read everything (not just first)
}
do
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
bool isEmptyElement = reader.IsEmptyElement;
while (reader.MoveToNextAttribute())
{
if ((object)reader.NamespaceURI == (object)xmlnsUri)
{
if (reader.Prefix.Length == 0)
{
// Default namespace declaration "xmlns"
Debug.Assert(reader.LocalName == "xmlns");
writer.WriteAttributeString("", "xmlns", xmlnsUri, reader.Value);
}
else
{
Debug.Assert(reader.Prefix == "xmlns");
writer.WriteAttributeString("xmlns", reader.LocalName, xmlnsUri, reader.Value);
}
}
else
{
writer.WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
writer.WriteString(reader.Value);
writer.WriteEndAttribute();
}
}
reader.MoveToElement();
if (isEmptyElement)
{
// there might still be a value, if there is a default value specified in the schema
writer.WriteEndElement();
}
else
{
level++;
}
break;
case XmlNodeType.EndElement:
writer.WriteFullEndElement();
//should not read beyond the level of the reader's original position.
level--;
break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
writer.WriteString(reader.Value);
break;
case XmlNodeType.SignificantWhitespace:
case XmlNodeType.Whitespace:
writer.WriteString(reader.Value);
break;
case XmlNodeType.Comment:
writer.WriteComment(reader.Value);
break;
case XmlNodeType.ProcessingInstruction:
writer.WriteProcessingInstruction(reader.LocalName, reader.Value);
break;
case XmlNodeType.EntityReference:
reader.ResolveEntity();
break;
case XmlNodeType.EndEntity:
case XmlNodeType.None:
case XmlNodeType.DocumentType:
case XmlNodeType.XmlDeclaration:
break;
case XmlNodeType.Attribute:
if ((object)reader.NamespaceURI == (object)xmlnsUri)
{
if (reader.Prefix.Length == 0)
{
// Default namespace declaration "xmlns"
Debug.Assert(reader.LocalName == "xmlns");
writer.WriteAttributeString("", "xmlns", xmlnsUri, reader.Value);
}
else
{
Debug.Assert(reader.Prefix == "xmlns");
//.........这里部分代码省略.........
示例2: LoadFromReader
//.........这里部分代码省略.........
{
case XmlNodeType.Element:
{
bool isEmptyElement = reader.IsEmptyElement;
builder.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.BaseURI);
// Add attribute and namespace nodes to element
while (reader.MoveToNextAttribute())
{
string namespaceUri = reader.NamespaceURI;
if ((object)namespaceUri == (object)xmlnsUri)
{
if (reader.Prefix.Length == 0)
{
// Default namespace declaration "xmlns"
Debug.Assert(reader.LocalName == "xmlns");
builder.WriteNamespaceDeclaration(string.Empty, reader.Value);
}
else
{
Debug.Assert(reader.Prefix == "xmlns");
builder.WriteNamespaceDeclaration(reader.LocalName, reader.Value);
}
}
else
{
builder.WriteStartAttribute(reader.Prefix, reader.LocalName, namespaceUri);
builder.WriteString(reader.Value, TextBlockType.Text);
builder.WriteEndAttribute();
}
}
if (isEmptyElement)
builder.WriteEndElement(true);
break;
}
case XmlNodeType.EndElement:
builder.WriteEndElement(false);
break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
builder.WriteString(reader.Value, TextBlockType.Text);
break;
case XmlNodeType.SignificantWhitespace:
if (reader.XmlSpace == XmlSpace.Preserve)
builder.WriteString(reader.Value, TextBlockType.SignificantWhitespace);
else
// Significant whitespace without xml:space="preserve" is not significant in XPath/XQuery data model
goto case XmlNodeType.Whitespace;
break;
case XmlNodeType.Whitespace:
// We intentionally ignore the reader.XmlSpace property here and blindly trust
// the reported node type. If the reported information is not in sync
// (in this case if the reader.XmlSpace == Preserve) then we make the choice
// to trust the reported node type. Since we have no control over the input reader
// we can't even assert here.
// Always filter top-level whitespace
if (space == XmlSpace.Preserve && (!topLevelReader || reader.Depth != 0))
builder.WriteString(reader.Value, TextBlockType.Whitespace);
break;
case XmlNodeType.Comment:
builder.WriteComment(reader.Value);
break;
case XmlNodeType.ProcessingInstruction:
builder.WriteProcessingInstruction(reader.LocalName, reader.Value, reader.BaseURI);
break;
case XmlNodeType.EntityReference:
reader.ResolveEntity();
break;
case XmlNodeType.DocumentType:
// Create ID tables
IDtdInfo info = reader.DtdInfo;
if (info != null)
builder.CreateIdTables(info);
break;
case XmlNodeType.EndEntity:
case XmlNodeType.None:
case XmlNodeType.XmlDeclaration:
break;
}
}
while (reader.Read());
}
finally
{
builder.Close();
}
}
示例3: ReadChildNodes
private void ReadChildNodes( XPathContainer parent, string parentBaseUri, XmlReader reader, PositionInfo positionInfo ) {
do {
documentIndex++;
switch( reader.NodeType ) {
case XmlNodeType.Element: {
string baseUri = reader.BaseURI;
XPathElement e = null;
if( reader.IsEmptyElement ) {
e = new XPathEmptyElement( reader.Prefix, reader.LocalName, reader.NamespaceURI, positionInfo.LineNumber, positionInfo.LinePosition, parent.topNamespace, documentIndex );
ReadAttributes( e, reader );
}
else {
e = new XPathElement( reader.Prefix, reader.LocalName, reader.NamespaceURI, positionInfo.LineNumber, positionInfo.LinePosition, parent.topNamespace, documentIndex );
ReadAttributes( e, reader );
reader.Read();
ReadChildNodes( e, baseUri, reader, positionInfo );
}
if (parentBaseUri != baseUri) {
// We can't user Ref.Equial Because Reader fails to fully atomize base Uri.
if (elementBaseUriMap == null) {
elementBaseUriMap = new Hashtable();
}
elementBaseUriMap[e] = baseUri;
}
parent.AppendChild( e );
break;
}
case XmlNodeType.Comment:
parent.AppendChild( new XPathComment( reader.Value, documentIndex ) );
break;
case XmlNodeType.ProcessingInstruction:
parent.AppendChild( new XPathProcessingInstruction( reader.LocalName, reader.Value, documentIndex ) );
break;
case XmlNodeType.SignificantWhitespace:
if( reader.XmlSpace == XmlSpace.Preserve ) {
parent.AppendSignificantWhitespace( reader.Value, positionInfo.LineNumber, positionInfo.LinePosition, documentIndex );
}
else {
// SWS without xml:space='preserve' is not really significant for XPath.
// so we treat it as just WS
goto case XmlNodeType.Whitespace;
}
break;
case XmlNodeType.Whitespace:
if( space == XmlSpace.Preserve ) {
parent.AppendWhitespace( reader.Value, positionInfo.LineNumber, positionInfo.LinePosition, documentIndex );
}
break;
case XmlNodeType.CDATA:
case XmlNodeType.Text:
parent.AppendText( reader.Value, positionInfo.LineNumber, positionInfo.LinePosition, documentIndex );
break;
case XmlNodeType.EntityReference:
reader.ResolveEntity();
reader.Read();
ReadChildNodes( parent, parentBaseUri, reader, positionInfo);
break;
case XmlNodeType.EndEntity:
case XmlNodeType.EndElement:
case XmlNodeType.None:
return;
case XmlNodeType.DocumentType:
XmlValidatingReader vr = reader as XmlValidatingReader;
if ( vr != null ) {
SchemaInfo info = vr.GetSchemaInfo();
if ( info != null ) {
GetIDInfo( info);
}
}
break;
case XmlNodeType.XmlDeclaration:
default:
break;
}
}while( reader.Read() );
}