private void SetEntityContent() { if (this.lastLinkedChild != null) { return; } XmlDocumentType documentType = this.OwnerDocument.DocumentType; if (documentType == null) { return; } DTDEntityDeclaration dtdentityDeclaration = documentType.DTD.EntityDecls[this.name]; if (dtdentityDeclaration == null) { return; } XmlNamespaceManager nsMgr = base.ConstructNamespaceManager(); XmlParserContext context = new XmlParserContext(this.OwnerDocument.NameTable, nsMgr, (documentType == null) ? null : documentType.DTD, this.BaseURI, this.XmlLang, this.XmlSpace, null); XmlTextReader xmlTextReader = new XmlTextReader(dtdentityDeclaration.EntityValue, XmlNodeType.Element, context); xmlTextReader.XmlResolver = this.OwnerDocument.Resolver; for (;;) { XmlNode xmlNode = this.OwnerDocument.ReadNode(xmlTextReader); if (xmlNode == null) { break; } base.InsertBefore(xmlNode, null, false, false); } }
private void ImportFromDTD() { this.entities = new XmlNamedNodeMap(this); this.notations = new XmlNamedNodeMap(this); foreach (DTDNode dtdnode in this.DTD.EntityDecls.Values) { DTDEntityDeclaration dtdentityDeclaration = (DTDEntityDeclaration)dtdnode; XmlNode namedItem = new XmlEntity(dtdentityDeclaration.Name, dtdentityDeclaration.NotationName, dtdentityDeclaration.PublicId, dtdentityDeclaration.SystemId, this.OwnerDocument); this.entities.SetNamedItem(namedItem); } foreach (DTDNode dtdnode2 in this.DTD.NotationDecls.Values) { DTDNotationDeclaration dtdnotationDeclaration = (DTDNotationDeclaration)dtdnode2; XmlNode namedItem2 = new XmlNotation(dtdnotationDeclaration.LocalName, dtdnotationDeclaration.Prefix, dtdnotationDeclaration.PublicId, dtdnotationDeclaration.SystemId, this.OwnerDocument); this.notations.SetNamedItem(namedItem2); } }
void SetEntityContent() { if (lastLinkedChild != null) { return; } XmlDocumentType doctype = OwnerDocument.DocumentType; if (doctype == null) { return; } #if NOT_PFX DTDEntityDeclaration decl = doctype.DTD.EntityDecls [name]; if (decl == null) { return; } XmlNamespaceManager nsmgr = this.ConstructNamespaceManager(); XmlParserContext ctx = new XmlParserContext(OwnerDocument.NameTable, nsmgr, doctype != null ? doctype.DTD : null, BaseURI, XmlLang, XmlSpace, null); XmlTextReader xmlReader = new XmlTextReader(decl.EntityValue, XmlNodeType.Element, ctx); xmlReader.XmlResolver = OwnerDocument.Resolver; do { XmlNode n = OwnerDocument.ReadNode(xmlReader); if (n == null) { break; } InsertBefore(n, null, false, false); } while (true); #endif }
private void ReadEntityValueDecl (DTDEntityDeclaration decl) { SkipWhitespace (); // quotation char will be finally removed on unescaping int quoteChar = ReadChar (); if (quoteChar != '\'' && quoteChar != '"') throw NotWFError ("quotation char was expected."); ClearValueBuffer (); while (PeekChar () != quoteChar) { int ch = ReadChar (); switch (ch) { case '%': string name = ReadName (); Expect (';'); if (decl.IsInternalSubset) throw NotWFError (String.Format ("Parameter entity is not allowed in internal subset entity '{0}'", name)); valueBuffer.Append (GetPEValue (name)); break; case -1: throw NotWFError ("unexpected end of stream."); default: if (this.normalization && XmlChar.IsInvalid (ch)) throw NotWFError ("Invalid character was found in the entity declaration."); AppendValueChar (ch); break; } } // string value = Dereference (CreateValueString (), false); string value = CreateValueString (); ClearValueBuffer (); Expect (quoteChar); decl.LiteralEntityValue = value; }
// The reader is positioned on the head of the name. private DTDEntityDeclaration ReadEntityDecl () { DTDEntityDeclaration decl = new DTDEntityDeclaration (DTD); decl.BaseURI = BaseURI; decl.XmlResolver = DTD.Resolver; decl.IsInternalSubset = this.processingInternalSubset; TryExpandPERef (); decl.Name = ReadName (); if (!SkipWhitespace ()) throw NotWFError ("Whitespace is required between name and content in DTD entity declaration."); TryExpandPERef (); if (PeekChar () == 'S' || PeekChar () == 'P') { // external entity ReadExternalID (); decl.PublicId = cachedPublicId; decl.SystemId = cachedSystemId; if (SkipWhitespace ()) { if (PeekChar () == 'N') { // NDataDecl Expect ("NDATA"); if (!SkipWhitespace ()) throw NotWFError ("Whitespace is required after NDATA."); decl.NotationName = ReadName (); // ndata_name } } if (decl.NotationName == null) { decl.Resolve (); ResolveExternalEntityReplacementText (decl); } else { // Unparsed entity. decl.LiteralEntityValue = String.Empty; decl.ReplacementText = String.Empty; } } else { // literal entity ReadEntityValueDecl (decl); ResolveInternalEntityReplacementText (decl); } SkipWhitespace (); // This expanding is only allowed as a non-validating parser. TryExpandPERef (); Expect ('>'); return decl; }