public void UseDtd(StreamReader dtd) { DTDParser parser = new DTDParser(dtd); m_Dtd = parser.Parse(true); ParseDtdIntoHashmap(); }
//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); } }
private bool PruefeNodePos(XmlNode node) { if (node is XmlWhitespace) { return(true); } if (this._dtd.IstDTDElementBekannt(DTD.GetElementNameFromNode(node))) { try { if (this.NodeChecker.IstDerNodeAnDieserStelleErlaubt(node)) { return(true); } this._fehlermeldungen.AppendFormat(ResReader.Reader.GetString("TagHierNichtErlaubt"), (object)node.Name); XMLCursorPos zuTestendeCursorPos = new XMLCursorPos(); zuTestendeCursorPos.CursorSetzen(node, XMLCursorPositionen.CursorAufNodeSelbstVorderesTag); string[] strArray = this.NodeChecker.AnDieserStelleErlaubteTags_(zuTestendeCursorPos, false, false); if ((uint)strArray.Length > 0U) { this._fehlermeldungen.Append(ResReader.Reader.GetString("ErlaubteTags")); foreach (object obj in strArray) { this._fehlermeldungen.AppendFormat("{0} ", obj); } } else { this._fehlermeldungen.Append(ResReader.Reader.GetString("AnDieserStelleKeineTagsErlaubt")); } return(false); } catch (DTD.XMLUnknownElementException ex) { this._fehlermeldungen.AppendFormat(ResReader.Reader.GetString("UnbekanntesElement"), (object)ex.ElementName); return(false); } } else { this._fehlermeldungen.AppendFormat(ResReader.Reader.GetString("UnbekanntesElement"), (object)DTD.GetElementNameFromNode(node)); return(false); } }
private void loadDTD(string dtdIdentifier) { DTD dtd = UseDtd(dtdIdentifier); if (dtd == null) { return; } 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)) { loadDTD(DTDs.DTDs.ENTITIES_MAPPING[key]); break; } } } }
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 XMLRegelwerk() { this._dtd = null; }
public XMLRegelwerk(DTD dtd) { this._dtd = dtd; }
public StartupDatei_XmlRegelwerk(DTD dtd) : base(dtd) { }
public DTD UseDtd(string dtdIdentifier) { string dtdCache = dtdIdentifier + ".cache"; //check to see if we have a cached version of this file #if USE_ISOLATED_STORAGE Stream stream = null; using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { string[] filenames = store.GetFileNames(dtdCache); if (filenames.Length > 0) { stream = new IsolatedStorageFileStream(dtdCache, FileMode.Open, FileAccess.Read, FileShare.None, store); } } if (stream != null) { try { m_DtdRegex.ReadFromCache(new StreamReader(stream, Encoding.UTF8)); } finally { stream.Close(); } } // NOTE: we could actually use the same code as below, which gives more control over the subdirectory and doesn't have any size limits: #else string dirpath = Path.Combine(ExternalFilesDataManager.STORAGE_FOLDER_PATH, m_DtdStoreDirName); //if (!Directory.Exists(dirpath)) //{ // Directory.CreateDirectory(dirpath); //} string path = Path.Combine(dirpath, dtdCache); if (File.Exists(path)) { Stream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read); try { m_DtdRegex.ReadFromCache(new StreamReader(stream, Encoding.UTF8)); } finally { stream.Close(); } return(null); } #endif //USE_ISOLATED_STORAGE else { //else read the .dtd file Stream dtdStream = DTDs.DTDs.Fetch(dtdIdentifier); if (dtdStream == null) { //DebugFix.Assert(false); #if DEBUG Debugger.Break(); #endif // DEBUG MissingDtdValidationError error = new MissingDtdValidationError() { DtdIdentifier = dtdIdentifier }; addValidationItem(error); return(null); } // NOTE: the Stream is automatically closed by the parser, see Scanner.ReadNextChar() DTDParser parser = new DTDParser(new StreamReader(dtdStream, Encoding.UTF8)); DTD dtd = parser.Parse(true); m_DtdRegex.ParseDtdIntoHashtable(dtd); return(dtd); } }
public AimlXmlRegelwerk(DTD dtd) : base(dtd) { }
public DTDPruefer(DTD dtd) { this._dtd = dtd; this.Reset(); }
public XMLRegelwerk() { this._dtd = (DTD)null; }