Types.cs :  » XML-Parsers » SAX.NET » Org » System » Xml » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » XML Parsers » SAX.NET 
SAX.NET » Org » System » Xml » Types.cs
// NO WARRANTY!  This code is in the Public Domain.
// Written by Karl Waclawek (karl@waclawek.net).

using System;
// using System.Collections.Generic; -- leave out for now, not needed (yet)

namespace Org.System.Xml{
  // public delegate string XmlStringIntern(string str); -- leave out for now, not needed (yet)

  /**<summary>Represents namespace aware name in XML.</summary> */
  public struct QName
  {
    private string localName;
    private string nsUri;

    /// <summary>Returns empty <see cref="QName"/> constant.</summary>
    /// <remarks>This implies that both, <see cref="LocalName"/> and
    /// <see cref="NsUri"/>, are the empty string.</remarks>
    public static QName Empty
    {
      get {
        QName result;
        result.localName = String.Empty;
        result.nsUri = String.Empty;
        return result;
      }
    }

    /// <overloads>
    /// <summary>Checks the <c>localname</c> and <c>nsUri</c> arguments and creates
    /// a new <see cref="QName"/> instance if they are well-formed.</summary>
    /// </overloads>
    /// <exception cref="ArgumentException">Thrown when the arguments are not well-formed.</exception>
    /// <remarks>Relative URIs will be rejected as namespace names since such use
    /// has been deprecated.</remarks>
    /// <param name="localName">Local part of qualified XML name.</param>
    /// <param name="nsUri">Namespace URI of qualified XML name.</param>
    /// <returns>Well-formed <see cref="QName"/> instance.</returns>
    public static QName Checked(string localName, string nsUri)
    {
      XmlChars.CheckNcName(localName);
      Uri uri = new Uri(nsUri);
      return new QName(localName, nsUri);
    }

    /// <param name="localName">Local part of qualified XML name.</param>
    /// <returns>Well-formed <see cref="QName"/> instance with empty namespace.</returns>
    public static QName Checked(string localName)
    {
      XmlChars.CheckNcName(localName);
      return new QName(localName);
    }

    /// <overloads>
    /// <summary>Initializes a new instance of the <c>QName</c> struct.</summary>
    /// <remarks><c>null</c> arguments will be converted to empty strings.
    /// Other than that there is no checking for well-formed arguments.</remarks>
    /// </overloads>
    /// <param name="localName">Local part of qualified XML name.</param>
    /// <param name="nsUri">Namespace URI of qualified XML name.</param>
    public QName(string localName, string nsUri)
    {
      this.localName = (localName == null) ? String.Empty : localName;
      this.nsUri = (nsUri == null) ? String.Empty : nsUri;
    }

    /// <param name="localName">Local part of qualified XML name.</param>
    public QName(string localName)
    {
      this.localName = (localName == null) ? String.Empty : localName;
      this.nsUri = String.Empty;
    }

    /// <summary>Indicates whether the <see cref="QName"/> is empty.</summary>
    public bool IsEmpty
    {
      get { return localName == String.Empty && nsUri == String.Empty; }
    }

    /// <summary>Local part of qualified XML name.</summary>
    public string LocalName
    {
      get { return localName; }
    }

    /// <summary>Namespace URI of qualified XML name.</summary>
    public string NsUri
    {
      get { return nsUri; }
    }

    /// <summary>Calculates hash value from local part and namespace URI.</summary>
    public override int GetHashCode()
    {
      return localName.GetHashCode() ^ nsUri.GetHashCode();
    }

    /// <summary>Overridden <c>Equals</c> method.</summary>
    public override bool Equals(object obj)
    {
      return obj is QName && this == (QName)obj;
    }

    /// <summary>Implementation of <c>==</c> operator.</summary>
    public static bool operator ==(QName x, QName y)
    {
      return x.localName == y.localName && x.nsUri == y.nsUri;
    }

    /// <summary>Implementation of <c>!=</c> operator.</summary>
    public static bool operator !=(QName x, QName y)
    {
      return !(x == y);
    }

    /// <summary>Returns string value of <see cref="QName"/>.</summary>
    /// <returns>String value in the format <b>{namespace}localname</b>,
    /// or just <b>localname</b> if there is no namespace defined.</returns>
    public override string ToString()
    {
      if (nsUri != String.Empty)
        return '{' + nsUri + '}' + localName;
      else
        return localName;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.