Windows Vista Forums

Problem with XmlTextWriter WriteFullEndElement method

  1. #1


    M1iS Guest

    Problem with XmlTextWriter WriteFullEndElement method

    I’m having a problem with writing full end elements on elements that are
    supposed to be empty strings. I’m calling the WriteFullEndElement method on
    my elements that are supposed to be empty however it is still creating a self
    closing tag. My code is posted below.

    Thanks,
    Scott


    //build xml document
    XmlTextWriter xw = new XmlTextWriter(docFullName, Encoding.UTF8);

    xw.WriteStartDocument();
    xw.WriteStartElement(app.XmlRootName);
    xw.WriteAttributeString("version", DateTime.Now.ToShortDateString());

    //get application translations
    DataTable translations =
    ApplicationController.GetTranslations(ApplicationID);
    int currentLanguageID = 0;
    int languageID;
    string languageName;
    string languageCode;
    string resourceCode;
    string translation;
    bool isFirstLanguageElement = true;
    bool isEmpty;
    int counter = 0;

    foreach (DataRow t in translations.Rows)
    {
    languageID = (int)t["LanguageID"];
    languageName = t["LanguageName"].ToString();
    languageCode = t["LanguageCode"].ToString();
    resourceCode = t["ResourceCode"].ToString();
    translation = t["Translation"].ToString();
    isEmpty = (bool)t["IsEmpty"];

    if (currentLanguageID != languageID)
    {
    if (isFirstLanguageElement)
    {
    currentLanguageID = languageID;

    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }

    isFirstLanguageElement = false;
    }
    else
    {
    xw.WriteEndElement();

    currentLanguageID = languageID;
    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }
    }
    }

    xw.WriteStartElement(app.XmlTranslationElementName);
    xw.WriteAttributeString("id", resourceCode);

    if (isEmpty)
    {
    xw.WriteString("");
    xw.WriteFullEndElement();
    }
    else
    {
    xw.WriteString(translation);
    xw.WriteEndElement();
    }

    counter += 1;
    if (counter == translations.Rows.Count)
    xw.WriteEndElement();
    }

    xw.WriteEndElement();
    xw.Close();

      My System SpecsSystem Spec

  2. #2


    Steve Eckhart Guest

    WriteFullEndElement Doesn't Write Closing Tag

    I'm having the same problem. Did you ever find a solution?



    M1i wrote:

    Problem with XmlTextWriter WriteFullEndElement method
    24-Nov-08

    I???m having a problem with writing full end elements on elements that are
    supposed to be empty strings. I???m calling the WriteFullEndElement method on
    my elements that are supposed to be empty however it is still creating a self
    closing tag. My code is posted below.

    Thanks,
    Scott


    //build xml document
    XmlTextWriter xw = new XmlTextWriter(docFullName, Encoding.UTF8);

    xw.WriteStartDocument();
    xw.WriteStartElement(app.XmlRootName);
    xw.WriteAttributeString("version", DateTime.Now.ToShortDateString());

    //get application translations
    DataTable translations =
    ApplicationController.GetTranslations(ApplicationID);
    int currentLanguageID = 0;
    int languageID;
    string languageName;
    string languageCode;
    string resourceCode;
    string translation;
    bool isFirstLanguageElement = true;
    bool isEmpty;
    int counter = 0;

    foreach (DataRow t in translations.Rows)
    {
    languageID = (int)t["LanguageID"];
    languageName = t["LanguageName"].ToString();
    languageCode = t["LanguageCode"].ToString();
    resourceCode = t["ResourceCode"].ToString();
    translation = t["Translation"].ToString();
    isEmpty = (bool)t["IsEmpty"];

    if (currentLanguageID != languageID)
    {
    if (isFirstLanguageElement)
    {
    currentLanguageID = languageID;

    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }

    isFirstLanguageElement = false;
    }
    else
    {
    xw.WriteEndElement();

    currentLanguageID = languageID;
    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }
    }
    }

    xw.WriteStartElement(app.XmlTranslationElementName);
    xw.WriteAttributeString("id", resourceCode);

    if (isEmpty)
    {
    xw.WriteString("");
    xw.WriteFullEndElement();
    }
    else
    {
    xw.WriteString(translation);
    xw.WriteEndElement();
    }

    counter += 1;
    if (counter == translations.Rows.Count)
    xw.WriteEndElement();
    }

    xw.WriteEndElement();
    xw.Close();

    Previous Posts In This Thread:

    On Monday, November 24, 2008 1:43 PM
    M1i wrote:

    Problem with XmlTextWriter WriteFullEndElement method
    I???m having a problem with writing full end elements on elements that are
    supposed to be empty strings. I???m calling the WriteFullEndElement method on
    my elements that are supposed to be empty however it is still creating a self
    closing tag. My code is posted below.

    Thanks,
    Scott


    //build xml document
    XmlTextWriter xw = new XmlTextWriter(docFullName, Encoding.UTF8);

    xw.WriteStartDocument();
    xw.WriteStartElement(app.XmlRootName);
    xw.WriteAttributeString("version", DateTime.Now.ToShortDateString());

    //get application translations
    DataTable translations =
    ApplicationController.GetTranslations(ApplicationID);
    int currentLanguageID = 0;
    int languageID;
    string languageName;
    string languageCode;
    string resourceCode;
    string translation;
    bool isFirstLanguageElement = true;
    bool isEmpty;
    int counter = 0;

    foreach (DataRow t in translations.Rows)
    {
    languageID = (int)t["LanguageID"];
    languageName = t["LanguageName"].ToString();
    languageCode = t["LanguageCode"].ToString();
    resourceCode = t["ResourceCode"].ToString();
    translation = t["Translation"].ToString();
    isEmpty = (bool)t["IsEmpty"];

    if (currentLanguageID != languageID)
    {
    if (isFirstLanguageElement)
    {
    currentLanguageID = languageID;

    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }

    isFirstLanguageElement = false;
    }
    else
    {
    xw.WriteEndElement();

    currentLanguageID = languageID;
    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }
    }
    }

    xw.WriteStartElement(app.XmlTranslationElementName);
    xw.WriteAttributeString("id", resourceCode);

    if (isEmpty)
    {
    xw.WriteString("");
    xw.WriteFullEndElement();
    }
    else
    {
    xw.WriteString(translation);
    xw.WriteEndElement();
    }

    counter += 1;
    if (counter == translations.Rows.Count)
    xw.WriteEndElement();
    }

    xw.WriteEndElement();
    xw.Close();


    Submitted via EggHeadCafe - Software Developer Portal of Choice
    MSDE (Microsoft Data Engine) Performance
    http://www.eggheadcafe.com/tutorials...data-engi.aspx

      My System SpecsSystem Spec

  3. #3


    Steve Eckhart Guest

    Problem with XmlTextWriter WriteFullEndElement method

    I'm having the same problem. Did anyone ever find a solution?



    M1i wrote:

    Problem with XmlTextWriter WriteFullEndElement method
    24-Nov-08

    I???m having a problem with writing full end elements on elements that are
    supposed to be empty strings. I???m calling the WriteFullEndElement method on
    my elements that are supposed to be empty however it is still creating a self
    closing tag. My code is posted below.

    Thanks,
    Scott


    //build xml document
    XmlTextWriter xw = new XmlTextWriter(docFullName, Encoding.UTF8);

    xw.WriteStartDocument();
    xw.WriteStartElement(app.XmlRootName);
    xw.WriteAttributeString("version", DateTime.Now.ToShortDateString());

    //get application translations
    DataTable translations =
    ApplicationController.GetTranslations(ApplicationID);
    int currentLanguageID = 0;
    int languageID;
    string languageName;
    string languageCode;
    string resourceCode;
    string translation;
    bool isFirstLanguageElement = true;
    bool isEmpty;
    int counter = 0;

    foreach (DataRow t in translations.Rows)
    {
    languageID = (int)t["LanguageID"];
    languageName = t["LanguageName"].ToString();
    languageCode = t["LanguageCode"].ToString();
    resourceCode = t["ResourceCode"].ToString();
    translation = t["Translation"].ToString();
    isEmpty = (bool)t["IsEmpty"];

    if (currentLanguageID != languageID)
    {
    if (isFirstLanguageElement)
    {
    currentLanguageID = languageID;

    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }

    isFirstLanguageElement = false;
    }
    else
    {
    xw.WriteEndElement();

    currentLanguageID = languageID;
    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }
    }
    }

    xw.WriteStartElement(app.XmlTranslationElementName);
    xw.WriteAttributeString("id", resourceCode);

    if (isEmpty)
    {
    xw.WriteString("");
    xw.WriteFullEndElement();
    }
    else
    {
    xw.WriteString(translation);
    xw.WriteEndElement();
    }

    counter += 1;
    if (counter == translations.Rows.Count)
    xw.WriteEndElement();
    }

    xw.WriteEndElement();
    xw.Close();

    Previous Posts In This Thread:

    On Monday, November 24, 2008 1:43 PM
    M1i wrote:

    Problem with XmlTextWriter WriteFullEndElement method
    I???m having a problem with writing full end elements on elements that are
    supposed to be empty strings. I???m calling the WriteFullEndElement method on
    my elements that are supposed to be empty however it is still creating a self
    closing tag. My code is posted below.

    Thanks,
    Scott


    //build xml document
    XmlTextWriter xw = new XmlTextWriter(docFullName, Encoding.UTF8);

    xw.WriteStartDocument();
    xw.WriteStartElement(app.XmlRootName);
    xw.WriteAttributeString("version", DateTime.Now.ToShortDateString());

    //get application translations
    DataTable translations =
    ApplicationController.GetTranslations(ApplicationID);
    int currentLanguageID = 0;
    int languageID;
    string languageName;
    string languageCode;
    string resourceCode;
    string translation;
    bool isFirstLanguageElement = true;
    bool isEmpty;
    int counter = 0;

    foreach (DataRow t in translations.Rows)
    {
    languageID = (int)t["LanguageID"];
    languageName = t["LanguageName"].ToString();
    languageCode = t["LanguageCode"].ToString();
    resourceCode = t["ResourceCode"].ToString();
    translation = t["Translation"].ToString();
    isEmpty = (bool)t["IsEmpty"];

    if (currentLanguageID != languageID)
    {
    if (isFirstLanguageElement)
    {
    currentLanguageID = languageID;

    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }

    isFirstLanguageElement = false;
    }
    else
    {
    xw.WriteEndElement();

    currentLanguageID = languageID;
    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }
    }
    }

    xw.WriteStartElement(app.XmlTranslationElementName);
    xw.WriteAttributeString("id", resourceCode);

    if (isEmpty)
    {
    xw.WriteString("");
    xw.WriteFullEndElement();
    }
    else
    {
    xw.WriteString(translation);
    xw.WriteEndElement();
    }

    counter += 1;
    if (counter == translations.Rows.Count)
    xw.WriteEndElement();
    }

    xw.WriteEndElement();
    xw.Close();

    On Thursday, January 21, 2010 11:59 AM
    Steve Eckhart wrote:

    WriteFullEndElement Doesn't Write Closing Tag
    I'm having the same problem. Did you ever find a solution?


    Submitted via EggHeadCafe - Software Developer Portal of Choice
    Office 2007 Beta now Available
    http://www.eggheadcafe.com/tutorials...-now-avai.aspx

      My System SpecsSystem Spec

  4. #4


    Steve Eckhart Guest

    Problem with XmlTextWriter WriteFullEndElement method

    I'm having the same issue. Did anyone ever find a solution?



    M1i wrote:

    Problem with XmlTextWriter WriteFullEndElement method
    24-Nov-08

    I???m having a problem with writing full end elements on elements that are
    supposed to be empty strings. I???m calling the WriteFullEndElement method on
    my elements that are supposed to be empty however it is still creating a self
    closing tag. My code is posted below.

    Thanks,
    Scott


    //build xml document
    XmlTextWriter xw = new XmlTextWriter(docFullName, Encoding.UTF8);

    xw.WriteStartDocument();
    xw.WriteStartElement(app.XmlRootName);
    xw.WriteAttributeString("version", DateTime.Now.ToShortDateString());

    //get application translations
    DataTable translations =
    ApplicationController.GetTranslations(ApplicationID);
    int currentLanguageID = 0;
    int languageID;
    string languageName;
    string languageCode;
    string resourceCode;
    string translation;
    bool isFirstLanguageElement = true;
    bool isEmpty;
    int counter = 0;

    foreach (DataRow t in translations.Rows)
    {
    languageID = (int)t["LanguageID"];
    languageName = t["LanguageName"].ToString();
    languageCode = t["LanguageCode"].ToString();
    resourceCode = t["ResourceCode"].ToString();
    translation = t["Translation"].ToString();
    isEmpty = (bool)t["IsEmpty"];

    if (currentLanguageID != languageID)
    {
    if (isFirstLanguageElement)
    {
    currentLanguageID = languageID;

    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }

    isFirstLanguageElement = false;
    }
    else
    {
    xw.WriteEndElement();

    currentLanguageID = languageID;
    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }
    }
    }

    xw.WriteStartElement(app.XmlTranslationElementName);
    xw.WriteAttributeString("id", resourceCode);

    if (isEmpty)
    {
    xw.WriteString("");
    xw.WriteFullEndElement();
    }
    else
    {
    xw.WriteString(translation);
    xw.WriteEndElement();
    }

    counter += 1;
    if (counter == translations.Rows.Count)
    xw.WriteEndElement();
    }

    xw.WriteEndElement();
    xw.Close();

    Previous Posts In This Thread:

    On Monday, November 24, 2008 1:43 PM
    M1i wrote:

    Problem with XmlTextWriter WriteFullEndElement method
    I???m having a problem with writing full end elements on elements that are
    supposed to be empty strings. I???m calling the WriteFullEndElement method on
    my elements that are supposed to be empty however it is still creating a self
    closing tag. My code is posted below.

    Thanks,
    Scott


    //build xml document
    XmlTextWriter xw = new XmlTextWriter(docFullName, Encoding.UTF8);

    xw.WriteStartDocument();
    xw.WriteStartElement(app.XmlRootName);
    xw.WriteAttributeString("version", DateTime.Now.ToShortDateString());

    //get application translations
    DataTable translations =
    ApplicationController.GetTranslations(ApplicationID);
    int currentLanguageID = 0;
    int languageID;
    string languageName;
    string languageCode;
    string resourceCode;
    string translation;
    bool isFirstLanguageElement = true;
    bool isEmpty;
    int counter = 0;

    foreach (DataRow t in translations.Rows)
    {
    languageID = (int)t["LanguageID"];
    languageName = t["LanguageName"].ToString();
    languageCode = t["LanguageCode"].ToString();
    resourceCode = t["ResourceCode"].ToString();
    translation = t["Translation"].ToString();
    isEmpty = (bool)t["IsEmpty"];

    if (currentLanguageID != languageID)
    {
    if (isFirstLanguageElement)
    {
    currentLanguageID = languageID;

    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }

    isFirstLanguageElement = false;
    }
    else
    {
    xw.WriteEndElement();

    currentLanguageID = languageID;
    xw.WriteStartElement("language");

    if (app.XmlLanguageElementIdType.ToLower() == "name")
    {
    xw.WriteAttributeString("name", languageName);
    }
    else if (app.XmlLanguageElementIdType.ToLower() == "code")
    {
    xw.WriteAttributeString("code", languageCode);
    }
    }
    }

    xw.WriteStartElement(app.XmlTranslationElementName);
    xw.WriteAttributeString("id", resourceCode);

    if (isEmpty)
    {
    xw.WriteString("");
    xw.WriteFullEndElement();
    }
    else
    {
    xw.WriteString(translation);
    xw.WriteEndElement();
    }

    counter += 1;
    if (counter == translations.Rows.Count)
    xw.WriteEndElement();
    }

    xw.WriteEndElement();
    xw.Close();

    On Thursday, January 21, 2010 11:59 AM
    Steve Eckhart wrote:

    WriteFullEndElement Doesn't Write Closing Tag
    I'm having the same problem. Did you ever find a solution?

    On Thursday, January 21, 2010 12:01 PM
    Steve Eckhart wrote:

    Problem with XmlTextWriter WriteFullEndElement method
    I'm having the same problem. Did anyone ever find a solution?


    Submitted via EggHeadCafe - Software Developer Portal of Choice
    KB905915 may break Internet Explorer
    http://www.eggheadcafe.com/tutorials...ak-intern.aspx

      My System SpecsSystem Spec

Problem with XmlTextWriter WriteFullEndElement method

Similar Threads
Thread Forum
Split Method
Hi there I'm trying to figure out what the following syntax for split means in the following line of the code arrTest.split('/') what does...
VB Script
method not many
to many method hheu..>>>don't worry
Vista mail
Method invocation failed because [System.String] doesn't contain a method
I can not see what is wrong with the following code: $ar = { $a = ] $this ::reverse($a) ::join('',$a) } $s = "One Two Three" Add-Member...
PowerShell
Doctype in XmlTextWriter
I am trying to generate SUN Identity Manager's XML file. It has following DOCTYPE (exported from the manager, I guess I can use same when...
PowerShell
can't get WMI method InParameters
Can someone confirm these errors ? , I'm on Vista RTM and PowerShell RC2 I think I did this successfull on RC2 + XP also I can succesfull...
PowerShell
Instr Method?
Is there a String Class method that is the equivalent of Vbscript Instr? Thank You, Fred Jacobowitz
PowerShell
Problem: Can not use <Reboot> or <Win32Shutdown> Method of Win32_OperatingSystem
Goal: ----- I need to be able to reboot machines remotely and I prefer not to use external apps. Tried: ------ $os = Get-WmiObject...
PowerShell