LookupPrefix() public method

public LookupPrefix ( string ns ) : string
ns string
return string
Example #1
0
        void WriteComplexTypeSample(XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
        {
            string ns = rootName.Namespace;

            if (rootName.Name.IndexOf("[]") != -1) rootName = arrayType;

            if (currentUse == SoapBindingUse.Encoded) {
                string pref = xtw.LookupPrefix(rootName.Namespace);
                if (pref == null) pref = "q1";
                xtw.WriteStartElement(pref, rootName.Name, rootName.Namespace);
                ns = "";
            }
            else
                xtw.WriteStartElement(rootName.Name, rootName.Namespace);

            if (id != -1) {
                xtw.WriteAttributeString("id", "id" + id);
                if (rootName != arrayType)
                    xtw.WriteAttributeString("type", XmlSchema.InstanceNamespace, GetQualifiedNameString(xtw, rootName));
            }

            WriteComplexTypeAttributes(xtw, stype);
            WriteComplexTypeElements(xtw, ns, stype);

            xtw.WriteEndElement();
        }
Example #2
0
        string GetQualifiedNameString(XmlTextWriter xtw, XmlQualifiedName qname)
        {
            string pref = xtw.LookupPrefix(qname.Namespace);
            if (pref != null) return pref + ":" + qname.Name;

            xtw.WriteAttributeString("xmlns", "q1", null, qname.Namespace);
            return "q1:" + qname.Name;
        }
Example #3
0
        private void ProcessFile_Click(object sender, RoutedEventArgs e)
        {
            // choose a file to process
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "Word files (*.doc)|*.doc;*.docx";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string doc_name;

                // init global data
                font_name_tbl = new ArrayList();
                font_char_cnt_tbl = new int[MAX_NUM_FONTS];
                font_glyph_cnt_tbl = new int[MAX_NUM_FONTS];

                // process the file
                doc_name = openFileDialog1.FileName;
                AnalyzeDocument(doc_name);

                // output the result in XML format

                int indx, num_fonts;

                XmlTextWriter writer = new XmlTextWriter("c:\\fontinfo.xml", null);
                //Use indenting for readability.
                writer.Formatting = Formatting.Indented;

                writer.WriteComment("FontAnalysis");

                //Write an element (this one is the root).
                writer.WriteStartElement("FontAnalysis");

                //Write the namespace declaration.
                writer.WriteAttributeString("xmlns", "font", null, "urn:FontAnalysis");

                writer.WriteStartElement("file");

                string prefix = writer.LookupPrefix("urn:FontAnalysis");
                writer.WriteStartAttribute(prefix, "file_name", "urn:FontAnalysis");
                writer.WriteString(doc_name);
                writer.WriteEndAttribute();

                num_fonts = font_name_tbl.Count;

                //display information for each font in document
                for (indx = 0; indx < num_fonts; indx++)
                {
                    //Write the font.
                    writer.WriteStartElement("font");
                    writer.WriteStartAttribute(prefix, "name", "urn:FontAnalysis");
                    writer.WriteString((string)font_name_tbl[indx]);
                    writer.WriteEndAttribute();

                    //Write the char count.
                    writer.WriteStartElement("char");
                    writer.WriteStartElement("count");
                    writer.WriteString(font_char_cnt_tbl[indx].ToString());
                    writer.WriteEndElement();
                    writer.WriteEndElement();

                    //Write the glyph count.
                    writer.WriteStartElement("glyph");
                    writer.WriteStartElement("count");
                    writer.WriteString(font_glyph_cnt_tbl[indx].ToString());
                    writer.WriteEndElement();
                    writer.WriteEndElement();

                    //Write the end tag for the font element.
                    writer.WriteEndElement();
                }

                //Write the end tag for the file element.
                writer.WriteEndElement();

                //Write the end tag for the FontAnalysis element.
                writer.WriteEndElement();

                //Write the XML to file and close the writer.
                writer.Flush();
                writer.Close();
            }
        }
Example #4
0
        private void BulkAnalyze_Click(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
            object oMissing = System.Reflection.Missing.Value;

            DialogResult result;

            // choose a directory
            result = folderBrowserDialog1.ShowDialog();
            if (true )//result )
            {
                selected_folder = folderBrowserDialog1.SelectedPath;

                if (selected_folder != "")
                {
                    string[] files = Directory.GetFiles(selected_folder, "*.docx");

                    XmlTextWriter writer = new XmlTextWriter("c:\\fontinfo.xml", null);
                    //Use indenting for readability.
                    writer.Formatting = Formatting.Indented;

                    writer.WriteComment("FontAnalysis");

                    //Write an element (this one is the root).
                    writer.WriteStartElement("FontAnalysis");
                    //Write the namespace declaration.
                    writer.WriteAttributeString("xmlns", "font", null, "urn:FontAnalysis");

                    foreach (string file in files)
                    {
                        // init global data
                        font_name_tbl = new ArrayList();
                        font_char_cnt_tbl = new int[MAX_NUM_FONTS];
                        font_glyph_cnt_tbl = new int[MAX_NUM_FONTS];

                        // for each doc file in the directory
                        // process the file and output the result
                        AnalyzeDocument(file);

                        // output the result in XML format

                        int indx, num_fonts;

                        writer.WriteStartElement("file");

                        string prefix = writer.LookupPrefix("urn:FontAnalysis");
                        writer.WriteStartAttribute(prefix, "file_name", "urn:FontAnalysis");
                        writer.WriteString(file);
                        writer.WriteEndAttribute();

                        num_fonts = font_name_tbl.Count;

                        //display information for each font in document
                        for (indx = 0; indx < num_fonts; indx++)
                        {
                            //Write the font.
                            writer.WriteStartElement("font");
                            writer.WriteStartAttribute(prefix, "name", "urn:FontAnalysis");
                            writer.WriteString((string)font_name_tbl[indx]);
                            writer.WriteEndAttribute();

                            //Write the char count.
                            writer.WriteStartElement("char");
                            writer.WriteStartElement("count");
                            writer.WriteString(font_char_cnt_tbl[indx].ToString());
                            writer.WriteEndElement();
                            writer.WriteEndElement();

                            //Write the glyph count.
                            writer.WriteStartElement("glyph");
                            writer.WriteStartElement("count");
                            writer.WriteString(font_glyph_cnt_tbl[indx].ToString());
                            writer.WriteEndElement();
                            writer.WriteEndElement();

                            //Write the end tag for the font element.
                            writer.WriteEndElement();
                        }

                        //Write the end tag for the file element.
                        writer.WriteEndElement();
                    }

                    //Write the end tag for the FontAnalysis element.
                    writer.WriteEndElement();

                    //Write the XML to file and close the writer.
                    writer.Flush();
                    writer.Close();
                }
            }
            // end the Wrrd App
            oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
        }
Example #5
0
		string GetQualifiedName (XmlTextWriter tw, string namspace, string localName)
		{
			return tw.LookupPrefix (namspace) + ":" + localName;
		}
Example #6
0
		public void ExportTypes (ServiceType[] servicetypes, SdlType sdltype, XmlTextWriter tw)
		{
			if (sdltype == SdlType.Sdl)	// Obsolete, we don't support this
				throw new NotSupportedException ();

			if (servicetypes.Length == 0) return;
			Type maint = servicetypes [0].ObjectType;
			
			Hashtable dataTypes = new Hashtable (); 
			ArrayList services = new ArrayList ();
			FindTypes (servicetypes, dataTypes, services);
			
			if (services.Count > 0)
				maint = ((ServiceType) services[0]).ObjectType;
			
			string serviceNs = GetXmlNamespace (maint, null);
			
			tw.Formatting = Formatting.Indented;
			tw.WriteStartElement ("definitions", MetaData.WsdlNamespace);
			tw.WriteAttributeString ("name", maint.Name);
			tw.WriteAttributeString ("targetNamespace", serviceNs);
			tw.WriteAttributeString ("xmlns", MetaData.XmlnsNamespace, MetaData.WsdlNamespace);
			tw.WriteAttributeString ("xmlns", "tns", MetaData.XmlnsNamespace, serviceNs);
			tw.WriteAttributeString ("xmlns", "xsd", MetaData.XmlnsNamespace, MetaData.SchemaNamespace);
			tw.WriteAttributeString ("xmlns", "xsi", MetaData.XmlnsNamespace, MetaData.SchemaInstanceNamespace);
			tw.WriteAttributeString ("xmlns", "suds", MetaData.XmlnsNamespace, MetaData.SudsNamespace);
			tw.WriteAttributeString ("xmlns", "wsdl", MetaData.XmlnsNamespace, MetaData.WsdlNamespace);
			tw.WriteAttributeString ("xmlns", "soapenc", MetaData.XmlnsNamespace, MetaData.SoapEncodingNamespace);
			tw.WriteAttributeString ("xmlns", "soap", MetaData.XmlnsNamespace, MetaData.SoapNamespace);
			
			int nums = 0;
			foreach (DictionaryEntry entry in dataTypes)
			{
				string ns = (string) entry.Key;
				if (tw.LookupPrefix (ns) != null) continue;
				tw.WriteAttributeString ("xmlns", "ns"+nums, MetaData.XmlnsNamespace, ns);
				nums++;
			}
			
			// Schema
			
			if (dataTypes.Count > 0)
			{
				tw.WriteStartElement ("types", MetaData.WsdlNamespace);
				foreach (DictionaryEntry entry in dataTypes)
				{
					SchemaInfo sinfo = (SchemaInfo) entry.Value;
					if (sinfo == null || sinfo.Types.Count == 0) continue;
					
					tw.WriteStartElement ("s", "schema", MetaData.SchemaNamespace);
					tw.WriteAttributeString ("targetNamespace", (string) entry.Key);
					tw.WriteAttributeString ("elementFormDefault", "unqualified");
					tw.WriteAttributeString ("attributeFormDefault", "unqualified");
					
					foreach (string ns in sinfo.Imports)
					{
						if (ns == (string) entry.Key) continue;
						tw.WriteStartElement ("import", MetaData.SchemaNamespace);
						tw.WriteAttributeString ("namespace", ns);
						tw.WriteEndElement ();
					}
					
					foreach (Type type in sinfo.Types)
						WriteDataTypeSchema (tw, type);
						
					tw.WriteEndElement ();
				}
				tw.WriteEndElement ();
			}
			
			// Bindings
			
/*			foreach (ServiceType st in servicetypes)
				WriteServiceBinding (tw, st);
*/
			foreach (ServiceType st in services)
				WriteServiceBinding (tw, st, dataTypes);

			// Service element
			
			tw.WriteStartElement ("service", MetaData.WsdlNamespace);
			if (services.Count > 0)
				tw.WriteAttributeString ("name", GetServiceName (maint));
			else
				tw.WriteAttributeString ("name", "Service");

			foreach (ServiceType st in services)
			{
				WriteServiceType (tw, st);
			}
			tw.WriteEndElement ();

			// Closing

			tw.WriteEndElement ();
			tw.Flush ();
		}