Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Problem with XmlTextWriter WriteFullEndElement method

Reply
 
Old 11-24-2008   #1 (permalink)
M1iS


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
Resync method .NET General
method not many Vista mail
Method invocation failed because [System.String] doesn't contain a method PowerShell
Doctype in XmlTextWriter PowerShell
Problem: Can not use <Reboot> or <Win32Shutdown> Method of Win32_OperatingSystem PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46