Xml file issue

Add-in Express™ Support Service
That's what is more important than anything else

Xml file issue
Xml display error msg and create new version on my desktop  
Samar QM




Posts: 2
Joined: 2012-12-05
Good Day

I am creating my first internet explore add-in , my add-in combine between SR and TTS, the user will say any word and if the word in xml file the add-in will generate URL if not the add-in will display error MSG , also the user can add new word to xml file . the problem that I am facing now when setup my add-in and run it on internet explore error msg display and when click continue the new version of xml file will create on my desktop ,I saved xml file in debug file .

User added an image

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.Xml;

namespace MyIEAddon1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SpeechSynthesizer audio = new SpeechSynthesizer();// repeat what i say in computer speech
            if (textBox1.Text == "" | textBox1.Text == " " | textBox1.Text == "  " | textBox1.Text == null)
            {
                MessageBox.Show("No word entered, Please enter your word ", "Error Message");
            }

            else
            {// (!string.IsNullOrEmpty(textBox1.Text))   // (listBox1.Items.Contains(textBox1.Text))

                if (!string.IsNullOrEmpty(textBox1.Text) && listBox1.Items.OfType<string>().Select(p => p.ToUpper()).Contains(textBox1.Text.ToUpper()))  // 
                {
                    MessageBox.Show("Sorry, Word that you try to add is already on the XML file", "Error Message");
                    textBox1.Text = " ";
                }

                else
                {
                    listBox1.Items.Add(textBox1.Text);
                }
                textBox1.Text = "";

            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            button4.Enabled = true; // disable save xml file
            button5.Enabled = false; //  enable load grammar to load grammar from xml file
            button3.Enabled = true; //  disable add button  

            XmlTextReader reader = new XmlTextReader("Grammar.xml");
            XmlNodeType type;

            while (reader.Read())
            {
                type = reader.NodeType;

                if (type == XmlNodeType.Element)
                {

                    if (reader.Name == "item")
                    {
                        reader.Read();

                        listBox1.Items.Add(reader.Value);
                    }
                }
            }

            reader.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            button5.Enabled = false; // disable load xml file
            button4.Enabled = true;  // enable save xml file

            try
            {
                XmlTextWriter writer = new XmlTextWriter("Grammar.xml", Encoding.UTF8);
                writer.Formatting = Formatting.Indented;

                writer.WriteStartDocument();
                writer.WriteStartElement("grammar");
                writer.WriteAttributeString("xmlns", "http://www.w3.org/2001/06/grammar");
                writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
                writer.WriteAttributeString("xml:lang", "en-US");
                writer.WriteAttributeString("version", "1.0");
                writer.WriteAttributeString("root", "command1");
                writer.WriteStartElement("rule ");
                writer.WriteAttributeString("id", "command1");
                writer.WriteAttributeString("scope", "public");
                writer.WriteStartElement("one-of");


                foreach (string item in listBox1.Items)
                {
                    writer.WriteStartElement("item");
                    writer.WriteString(item);
                    writer.WriteEndElement(); //WORD
                }

                writer.WriteEndElement(); //COMMAND
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndDocument();// End Document

                writer.Close();
                MessageBox.Show("THE NEW WORDS ADD TO THE XML FILE !!", "Message");
            }
            catch
            { MessageBox.Show("InvalidCastException"); }

            int num = listBox1.Items.Count;  //  to count tne number of words will do the folowing :
            string m;
            m = Convert.ToString(num);

            foreach (string item in listBox1.Items)

                label4.Text = m;
        }
    }
}




this is my xml file


<?xml version="1.0" encoding="utf-8"?>
<grammar xmlns="http://www.w3.org/2001/06/grammar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en-US" version="1.0" root="command1">
  <one-of>
    <item>it322</item>
    <item>it419</item>
    <item>it211</item>
    <item>it327</item>
    <item>itnetwork2</item>
    <item>it212</item>
    <item>itnetwork1</item>
    <item>it321</item>
    <item>it323</item>
    <item>331it</item>
    <item>itttttt</item>
    <item>1111</item>
  </one-of>
</grammar>


Thank u
Posted 05 Dec, 2012 05:47:45 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Samar,

I cannot say that I understand what you do or what occurs. It looks like you create a file and get an exception. First off, you need to read the description of the method that opens the file and modify your installer so that it places the XML to a location where your add-on can find it. Also, please read HowTo: Deal with Protected Mode API in Internet Explorer 7 and IE8 at http://www.add-in-express.com/creating-addins-blog/2009/06/12/internet-explorer-protected-mode-api/.

You should understand that IE will create many instances of your IE add-on. So you must be prepared that several instances of your form will be shown. Please read the section "Windowing and Threading" in the manual, see {Add-in Express}\Docs\adxie.pdf.

Also, I suggest that you consider usin an ADX IE Bar to show your controls, not just System.Windows.Forms.Form. The fact is that non-modal forms interfere with the windowing of IE. Please have a look into the manual, the section is Custom Bars in IE.


Andrei Smolin
Add-in Express Team Leader
Posted 05 Dec, 2012 06:39:36 Top