GoDigram for .NET Framework and .NET Core
Northwoods.Go.Xml Namespace / GoXmlWriter Class / SetNamespaceUri Method
must not be null
if null this method removes any URI associated with the prefix
In This Topic
    SetNamespaceUri Method
    In This Topic
    Define the namespace URI for a prefix string, used when writing prefixed attribute names.
    Syntax
    public virtual void SetNamespaceUri( 
       string prefix,
       string uri
    )

    Parameters

    prefix
    must not be null
    uri
    if null this method removes any URI associated with the prefix
    Remarks
    This should be called to establish a namespace URI for a prefix before calling WriteStartElement(String) or WriteAttrVal with a name that has that prefix. To specify the default namespace for the root element, set the DefaultNamespace property. Calls to this method before a call to a Generate method will result in the addition of "xmlns:prefix" attributes in the root element.
    Example

    As an example, consider the following code adapted from the GoSvg implementation: GoXmlWriter w = ... w.DefaultNamespace = "http://www.w3.org/2000/svg"; w.SetNamespaceUri("xlink", "http://www.w3.org/1999/xlink");

    The above code causes the root element to have an "xmlns" attribute. It also defines a prefix, "xlink", that refers to a particular namespace URI. The result may look like: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> ... </svg>

    By calling SetNamespaceUri, you can then define a GoXmlTransformer with code such as: public override void GenerateBody(Object obj) { base.GenerateBody(obj); GoImage img = (GoImage)obj; Image image = img.Image; String id = this.Writer.FindShared(image); if (id != null) { WriteStartElement("use"); WriteAttrVal("xlink:href", "#S" + id); WriteEndElement(); } }

    The above transformer method example is simplified from the code used by the SVG transformer for GoImages, where there needs to be a link to the element representing the actual Image.

    See Also