// Creates a XmlValidatingReader suitable for parsing InnerXml strings private XmlReader CreateInnerXmlValidatingReader(String xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc) { XmlNodeType contentNT = nt; if (contentNT == XmlNodeType.Entity || contentNT == XmlNodeType.EntityReference) { contentNT = XmlNodeType.Element; } XmlValidatingReader xmlvr = new XmlValidatingReader(xmlFragment, contentNT, context); if (doc.DocumentType != null) { xmlvr.Namespaces = doc.DocumentType.ParseWithNamespaces; } if (doc.HasSetResolver) { xmlvr.XmlResolver = doc.GetResolver(); } xmlvr.ValidationType = ValidationType.None; if (!(doc.ActualLoadingStatus)) { xmlvr.DisableUndeclaredEntityCheck = true; } // all these settings are alreay the default setting in XmlTextReader xmlvr.EntityHandling = EntityHandling.ExpandCharEntities; if (nt == XmlNodeType.Entity || nt == XmlNodeType.EntityReference) { xmlvr.Read(); //this will skip the first element "wrapper" xmlvr.ResolveEntity(); } return(xmlvr); }
internal void ParseDocumentType(XmlDocumentType dtNode) { XmlDocument ownerDocument = dtNode.OwnerDocument; if (ownerDocument.HasSetResolver) { this.ParseDocumentType(dtNode, true, ownerDocument.GetResolver()); } else { this.ParseDocumentType(dtNode, false, null); } }
#pragma warning disable 618 // Creates a XmlValidatingReader suitable for parsing InnerXml strings private XmlReader CreateInnerXmlReader(String xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc) { XmlNodeType contentNT = nt; if (contentNT == XmlNodeType.Entity || contentNT == XmlNodeType.EntityReference) { contentNT = XmlNodeType.Element; } XmlTextReaderImpl tr = new XmlTextReaderImpl(xmlFragment, contentNT, context); tr.XmlValidatingReaderCompatibilityMode = true; if (doc.HasSetResolver) { tr.XmlResolver = doc.GetResolver(); } if (!(doc.ActualLoadingStatus)) { tr.DisableUndeclaredEntityCheck = true; } Debug.Assert(tr.EntityHandling == EntityHandling.ExpandCharEntities); XmlDocumentType dtdNode = doc.DocumentType; if (dtdNode != null) { tr.Namespaces = dtdNode.ParseWithNamespaces; if (dtdNode.DtdSchemaInfo != null) { tr.SetDtdInfo(dtdNode.DtdSchemaInfo); } else { IDtdParser dtdParser = DtdParser.Create(); XmlTextReaderImpl.DtdParserProxy proxy = new XmlTextReaderImpl.DtdParserProxy(tr); IDtdInfo dtdInfo = dtdParser.ParseFreeFloatingDtd(context.BaseURI, context.DocTypeName, context.PublicId, context.SystemId, context.InternalSubset, proxy); // TODO: Change all of XmlDocument to IDtdInfo interfaces dtdNode.DtdSchemaInfo = dtdInfo as SchemaInfo; tr.SetDtdInfo(dtdInfo); } } if (nt == XmlNodeType.Entity || nt == XmlNodeType.EntityReference) { tr.Read(); //this will skip the first element "wrapper" tr.ResolveEntity(); } return(tr); }
internal void ParseDocumentType(XmlDocumentType dtNode) { XmlDocument doc = dtNode.OwnerDocument; //if xmlresolver is set on doc, use that one, otherwise use the default one being created by xmlvalidatingreader if (doc.HasSetResolver) { ParseDocumentType(dtNode, true, doc.GetResolver()); } else { ParseDocumentType(dtNode, false, null); } }
private XmlReader CreateInnerXmlReader(string xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc) { XmlNodeType fragType = nt; switch (fragType) { case XmlNodeType.Entity: case XmlNodeType.EntityReference: fragType = XmlNodeType.Element; break; } XmlTextReaderImpl reader = new XmlTextReaderImpl(xmlFragment, fragType, context) { XmlValidatingReaderCompatibilityMode = true }; if (doc.HasSetResolver) { reader.XmlResolver = doc.GetResolver(); } if (!doc.ActualLoadingStatus) { reader.DisableUndeclaredEntityCheck = true; } XmlDocumentType documentType = doc.DocumentType; if (documentType != null) { reader.Namespaces = documentType.ParseWithNamespaces; if (documentType.DtdSchemaInfo != null) { reader.SetDtdInfo(documentType.DtdSchemaInfo); } else { IDtdParser parser = DtdParser.Create(); XmlTextReaderImpl.DtdParserProxy adapter = new XmlTextReaderImpl.DtdParserProxy(reader); IDtdInfo newDtdInfo = parser.ParseFreeFloatingDtd(context.BaseURI, context.DocTypeName, context.PublicId, context.SystemId, context.InternalSubset, adapter); documentType.DtdSchemaInfo = newDtdInfo as SchemaInfo; reader.SetDtdInfo(newDtdInfo); } } if ((nt == XmlNodeType.Entity) || (nt == XmlNodeType.EntityReference)) { reader.Read(); reader.ResolveEntity(); } return(reader); }
private XmlReader CreateInnerXmlReader(string xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc) { XmlNodeType fragType = nt; switch (fragType) { case XmlNodeType.Entity: case XmlNodeType.EntityReference: fragType = XmlNodeType.Element; break; } XmlTextReaderImpl reader = new XmlTextReaderImpl(xmlFragment, fragType, context) { XmlValidatingReaderCompatibilityMode = true }; if (doc.HasSetResolver) { reader.XmlResolver = doc.GetResolver(); } if (!doc.ActualLoadingStatus) { reader.DisableUndeclaredEntityCheck = true; } XmlDocumentType documentType = doc.DocumentType; if (documentType != null) { reader.Namespaces = documentType.ParseWithNamespaces; if (documentType.DtdSchemaInfo != null) { reader.SetDtdInfo(documentType.DtdSchemaInfo); } else { IDtdParser parser = DtdParser.Create(); XmlTextReaderImpl.DtdParserProxy adapter = new XmlTextReaderImpl.DtdParserProxy(reader); IDtdInfo newDtdInfo = parser.ParseFreeFloatingDtd(context.BaseURI, context.DocTypeName, context.PublicId, context.SystemId, context.InternalSubset, adapter); documentType.DtdSchemaInfo = newDtdInfo as SchemaInfo; reader.SetDtdInfo(newDtdInfo); } } if ((nt == XmlNodeType.Entity) || (nt == XmlNodeType.EntityReference)) { reader.Read(); reader.ResolveEntity(); } return reader; }
// Creates a XmlValidatingReader suitable for parsing InnerXml strings private XmlReader CreateInnerXmlValidatingReader( String xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc ) { XmlNodeType contentNT = nt; if ( contentNT == XmlNodeType.Entity || contentNT == XmlNodeType.EntityReference ) contentNT = XmlNodeType.Element; XmlValidatingReader xmlvr = new XmlValidatingReader( xmlFragment, contentNT, context); if( doc.DocumentType != null ) xmlvr.Namespaces = doc.DocumentType.ParseWithNamespaces; if ( doc.HasSetResolver ) xmlvr.XmlResolver = doc.GetResolver(); xmlvr.ValidationType = ValidationType.None; if( !( doc.ActualLoadingStatus ) ) xmlvr.DisableUndeclaredEntityCheck = true; // all these settings are alreay the default setting in XmlTextReader xmlvr.EntityHandling = EntityHandling.ExpandCharEntities; if ( nt == XmlNodeType.Entity || nt == XmlNodeType.EntityReference ) { xmlvr.Read(); //this will skip the first element "wrapper" xmlvr.ResolveEntity(); } return xmlvr; }
#pragma warning disable 618 // Creates a XmlValidatingReader suitable for parsing InnerXml strings private XmlReader CreateInnerXmlReader(String xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc) { XmlNodeType contentNT = nt; if (contentNT == XmlNodeType.Entity || contentNT == XmlNodeType.EntityReference) contentNT = XmlNodeType.Element; XmlTextReaderImpl tr = new XmlTextReaderImpl(xmlFragment, contentNT, context); tr.XmlValidatingReaderCompatibilityMode = true; if (doc.HasSetResolver) { tr.XmlResolver = doc.GetResolver(); } if (!(doc.ActualLoadingStatus)) { tr.DisableUndeclaredEntityCheck = true; } Debug.Assert(tr.EntityHandling == EntityHandling.ExpandCharEntities); XmlDocumentType dtdNode = doc.DocumentType; if (dtdNode != null) { tr.Namespaces = dtdNode.ParseWithNamespaces; if (dtdNode.DtdSchemaInfo != null) { tr.SetDtdInfo(dtdNode.DtdSchemaInfo); } else { IDtdParser dtdParser = DtdParser.Create(); XmlTextReaderImpl.DtdParserProxy proxy = new XmlTextReaderImpl.DtdParserProxy(tr); IDtdInfo dtdInfo = dtdParser.ParseFreeFloatingDtd(context.BaseURI, context.DocTypeName, context.PublicId, context.SystemId, context.InternalSubset, proxy); // TODO: Change all of XmlDocument to IDtdInfo interfaces dtdNode.DtdSchemaInfo = dtdInfo as SchemaInfo; tr.SetDtdInfo(dtdInfo); } } if (nt == XmlNodeType.Entity || nt == XmlNodeType.EntityReference) { tr.Read(); //this will skip the first element "wrapper" tr.ResolveEntity(); } return tr; }