//public void Reset() //{ // DtdRegexTable = null; //} //take a DtdSharp data structure and create a hashmap where //key: element name //value: regex representing the allowed children public void ParseDtdIntoHashtable(DTD dtd) { if (DtdRegexTable == null) { DtdRegexTable = new Dictionary <string, Regex>(); } var strBuilder = new StringBuilder(); foreach (DictionaryEntry entry in dtd.Elements) { DTDElement dtdElement = (DTDElement)entry.Value; #if NET40 strBuilder.Clear(); #else strBuilder.Length = 0; #endif //NET40 GenerateRegexForAllowedChildren(strBuilder, dtdElement.Content); string regexStr = strBuilder.ToString(); Regex regex = new Regex(regexStr); string key = dtdElement.Name.Replace(':', NAMESPACE_PREFIX_SEPARATOR); DtdRegexTable[key] = regex; //DtdRegexTable.Add(key, regex); } }
public virtual bool IstSchliessendesTagSichtbar(XmlNode xmlNode) { if (xmlNode is XmlText) { return(false); } DTDElement dtdElement = this._dtd.DTDElementByNode_(xmlNode, false); return(dtdElement == null || dtdElement.AlleElementNamenWelcheAlsDirektesChildZulaessigSind.Count > 1); }
//take a DtdSharp data structure and create a hashmap where //key: element name //value: regex representing the allowed children private void ParseDtdIntoHashmap() { m_DtdElementRegex = new Hashtable(); foreach (DictionaryEntry entry in m_Dtd.Elements) { DTDElement dtdElement = (DTDElement)entry.Value; string regexStr = GenerateRegexForAllowedChildren(dtdElement.Content); Regex regex = new Regex(regexStr); m_DtdElementRegex.Add(dtdElement.Name, regex); } }
private void initMixedContentXmlElementNamesFromDTD(string dtdUniqueResourceId, Stream dtdStream) { List <string> list; m_listOfMixedContentXmlElementNames.TryGetValue(dtdUniqueResourceId, out list); DebugFix.Assert(list != null); if (list == null) { return; } DTD dtd = null; try { // NOTE: the Stream is automatically closed by the parser, see Scanner.ReadNextChar() DTDParser parser = new DTDParser(new StreamReader(dtdStream, Encoding.UTF8)); dtd = parser.Parse(true); } catch (Exception ex) { #if DEBUG Debugger.Break(); #endif dtdStream.Close(); } if (dtd != null) { foreach (DictionaryEntry entry in dtd.Elements) { DTDElement dtdElement = (DTDElement)entry.Value; DTDItem item = dtdElement.Content; if (isMixedContent(item)) { if (!list.Contains(dtdElement.Name)) { list.Add(dtdElement.Name); } } } foreach (DictionaryEntry entry in dtd.Entities) { DTDEntity dtdEntity = (DTDEntity)entry.Value; if (dtdEntity.ExternalId == null) { continue; } string system = dtdEntity.ExternalId.System; if (dtdEntity.ExternalId is DTDPublic) { string pub = ((DTDPublic)dtdEntity.ExternalId).Pub; if (!string.IsNullOrEmpty(pub)) { system = pub; //.Replace(" ", "%20"); } } string normalisedUri = system.Replace("%20", " ").Replace(" //", "//").Replace("// ", "//"); foreach (String key in DTDs.DTDs.ENTITIES_MAPPING.Keys) { if (normalisedUri.Contains(key)) { string subResource = DTDs.DTDs.ENTITIES_MAPPING[key]; Stream stream = DTDs.DTDs.Fetch(subResource); if (stream != null) { initMixedContentXmlElementNamesFromDTD(dtdUniqueResourceId, stream); } else { #if DEBUG Debugger.Break(); #endif } break; } } } } }
public void AttributeAnzeigen() { this._attribute = (List <DTDAttribut>)null; this.lblFehler.Visible = false; if (this._xmlEditor != null && this._xmlEditor.RootNode != null && this._xmlEditor.CursorRoh.StartPos.Equals(this._xmlEditor.CursorRoh.EndPos)) { int num1 = 5; int num2 = num1; XmlNode xmlNode; switch (this._xmlEditor.CursorRoh.StartPos.PosAmNode) { case XMLCursorPositionen.CursorVorDemNode: case XMLCursorPositionen.CursorHinterDemNode: xmlNode = this._xmlEditor.CursorRoh.StartPos.AktNode.ParentNode; break; case XMLCursorPositionen.CursorAufNodeSelbstVorderesTag: case XMLCursorPositionen.CursorAufNodeSelbstHinteresTag: case XMLCursorPositionen.CursorInDemLeeremNode: xmlNode = this._xmlEditor.CursorRoh.StartPos.AktNode; break; case XMLCursorPositionen.CursorInnerhalbDesTextNodes: xmlNode = this._xmlEditor.CursorRoh.StartPos.AktNode; break; default: xmlNode = (XmlNode)null; break; } while (xmlNode is XmlText) { xmlNode = xmlNode.ParentNode; } if (xmlNode != null) { DTDElement dtdElement = (DTDElement)null; try { dtdElement = this._xmlEditor.Regelwerk.DTD.DTDElementByName(xmlNode.Name, true); } catch (DTD.XMLUnknownElementException ex) { Debugger.GlobalDebugger.Protokolliere(string.Format("unknown element {0} in {1}->{2}", (object)ex.ElementName, (object)this.Name, (object)"AttributeNeuAnzeigen")); this.lblFehler.Text = string.Format("unknown element '{0}'", (object)ex.ElementName); this.lblFehler.Visible = true; } if (dtdElement != null) { this._attribute = dtdElement.Attribute; if (this._attribute.Count > 0) { for (int index = 0; index < this._attribute.Count; ++index) { ucXMLEditAttribut ucXmlEditAttribut; if (index < this._attributEditFelder.Count) { ucXmlEditAttribut = (ucXMLEditAttribut)this._attributEditFelder[index]; } else { ucXmlEditAttribut = new ucXMLEditAttribut(); ucXmlEditAttribut.Parent = (Control)this; ucXmlEditAttribut.Top = num2; ucXmlEditAttribut.Left = num1; ucXmlEditAttribut.Width = 10; ucXmlEditAttribut.Visible = true; this._attributEditFelder.Add((object)ucXmlEditAttribut); } ucXmlEditAttribut.XMLEditor = this._xmlEditor; ucXmlEditAttribut.Node = xmlNode; ucXmlEditAttribut.Attribut = this._attribute[index]; ucXmlEditAttribut.NeuZeichnen(); num2 += ucXmlEditAttribut.Height; this.NichtMehrBenoetigteAttributEditFelderLoeschen(); foreach (Control control in this._attributEditFelder) { control.Width = this.ClientSize.Width - num1 * 2; } } } } } } this.NichtMehrBenoetigteAttributEditFelderLoeschen(); }