/*********************************************************************/
/* */
/* AgentService Framework */
/* www.agentservice.it */
/* */
/* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */
/* GNU Lesser General Public License */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation, */
/* version 2.1 of the License. */
/* */
/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public */
/* License along with this library; if not, write to the */
/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
/* Boston, MA 02111-1307, USA. */
/* */
/*********************************************************************/
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Collections;
namespace AgentService.Install.XmlDataModel
{
///
/// Class XmlSerializationHelper. Xml Wrapper class used
/// to read and write xml tags in the form of
/// <Name Value="" />. The tag name is specified
/// by the class which hold references to instances
/// of these objects. This is an halper class used
/// to read and write tags which contain only an attribute
/// with a string value. Either the name of the tag
/// or the name of the attribute can be specified.
///
class XmlSerializationHelper
{
///
/// Reads an XML tag with the specified structure.
///
/// XML tag name
/// XML attribute name
/// reader used to fecth data from the XML stream
/// XML attribute value
public static string ReadTag(string tagName, string tagAttributeName, XmlReader reader)
{
string attribute = null;
if (reader.LocalName.CompareTo(tagName) == 0)
{
if (reader.AttributeCount == 1)
{
if (reader.MoveToAttribute(tagAttributeName) == true)
{
attribute = reader.Value;
reader.ReadStartElement();
return attribute;
}
}
throw new XmlSchemaException(String.Format("the current tag [<{0}>] does not contain the attribute {1}", tagName, tagAttributeName), null);
}
throw new XmlSchemaException(String.Format("{0} tag expected", tagName), null);
}
///
/// Writes the XML tag representing a XML node with the
/// given tag name and only one attribute of the given
/// name.
///
/// tag name
/// tag attribute name
/// tag attribute value
/// writer used to write to the XML stream
public static void WriteTag(string tagName, string tagAttributeName, string tagAttributeValue, XmlWriter writer)
{
writer.WriteStartElement(tagName);
writer.WriteAttributeString(tagAttributeName, tagAttributeValue);
writer.WriteEndElement();
}
}
}