Ampersands in XML

Alright, hopefully someone will have an answer for this, or just explain it to me...

I'm working on WebDeploy, specifically a single bug I identified while trying to use WebDeploy to deploy Community Server :: Forums last week. The problem is that the VS.NET project file that is used, has a few File elements that contain ampersands within an attribute. Now I realize that you can have ampersands, but they must be in the format of "&", whereas these are just straight "&" in the attribute values.

My initial problem was that the Xml Document I was loading the project file into, would throw a FormatException, and ultimately not allow me to process that file. So, I bypassed this by using an XmlTextReader. I am now able to get the data I want, but the problem of the ampersands still exist. Whenever I hit those nodes, whammo! exception.

My questions to MS or the blogosphere:

1. How in the world did those ampersands get into the project file without being converted so that the project file is valid?
2. How in the world does VS.NET successfully open these projects without complaining to the user?

As of right now, I'm putting in a bugfix for WebDeploy that will not hault deployment if it comes across such a problem, however it will skip over the invalid files. Maybe someone can answer my questions and give me a good solution so that those files with the ampersand will get deployed along with everything else.

Also, because of this issue, I also had to create a recursive call to make sure that it doesn't bomb out on the reading, the following code is how I bypassed this:

private bool ReadReader(XmlTextReader reader)
{
bool read = false;
try
{
read = reader.Read();
}
catch
{
read = ReadReader(reader);
}
return read;
}

1 Comment

  • ...cause I dont think VS is actually using a true XML parser to read/write the project file...



    I've run into several of the same "oddities" with VS.NET Project files since B1...



    since when is

    <TAG

    ATTRIBUTE = "value"

    ATTRIBUTE2 = "value2"

    >

    a standard way of writing xml???

Comments have been disabled for this content.