SetAttribute xlink:href

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jvanulden

    #1

    SetAttribute xlink:href

    Hello all,

    I am having difficulty figuring out how to create an XmlElement and giving
    it an attribute that requires a namespace. Here is what I have so far which
    throws an exception because you can't have a : in an attribute name???

    XmlElement eOnlineResource = m_context.Creat eElement("Onlin eResource");

    eOnlineResource .SetAttribute(" xlink:href", "http://www.w3c.org/1999/xlink",
    sldUrl);

    Any help is appreciated.
  • dickster

    #2
    Re: SetAttribute xlink:href

    See: http://www.dotnet247.com/247referenc...43/216508.aspx

    -------------------------------------------------------------------------------------------------------------
    Dim xdoc As New XmlDocument
    Dim eOnlineResource As XmlElement

    xdoc.LoadXml("< root xmlns='DefaultN SDickster'
    xmlns:xlink='ht tp://www.w3c.org/1999/xlink'></root>")

    eOnlineResource =
    xdoc.CreateElem ent("eOnLineRes ource","Default NSDickster")

    eOnlineResource .SetAttribute(" href",
    "http://www.w3c.org/1999/xlink", "theValue")

    xdoc.FirstChild .AppendChild(eO nlineResource)

    -------------------------------------------------------------------------------------------------------------

    The prefix will be in the XML.

    Dickster

    Comment

    • jvanulden

      #3
      Re: SetAttribute xlink:href

      Thanks but that still doesn't work. I think it has to do with the fact that
      I am operating on a node and not a document. Here is my code:

      XmlNode sldUrlNode =
      layerNode.Selec tSingleNode("St yleList/Style/SLD/OnlineResource" );

      if (sldUrlNode == null)
      {
      // we need to create the SLD Node if it does not exist
      XmlElement eStyleList =
      m_context.Creat eElement("Style List");

      XmlElement eStyle = m_context.Creat eElement("Style ");
      eStyle.SetAttri bute("current", "1");

      eStyleList.Appe ndChild(eStyle) ;

      XmlElement eSLD = m_context.Creat eElement("SLD") ;

      XmlElement eName = m_context.Creat eElement("Name" );
      eName.InnerText = layerName;

      eSLD.AppendChil d(eName);

      XmlElement eOnlineResource =
      m_context.Creat eElement("Onlin eResource", "xlink");

      eOnlineResource .SetAttribute(" href",
      "http://www.w3.org/1999/xlink", sldUrl);

      eSLD.AppendChil d(eOnlineResour ce);

      eStyle.AppendCh ild(eSLD);

      layerNode.Appen dChild(eStyleLi st);

      }
      else
      {

      sldUrlNode.Attr ibutes[0].Value = sldUrl;
      }
      }
      }


      "dickster" wrote:
      See: http://www.dotnet247.com/247referenc...43/216508.aspx
      >
      -------------------------------------------------------------------------------------------------------------
      Dim xdoc As New XmlDocument
      Dim eOnlineResource As XmlElement
      >
      xdoc.LoadXml("< root xmlns='DefaultN SDickster'
      xmlns:xlink='ht tp://www.w3c.org/1999/xlink'></root>")
      >
      eOnlineResource =
      xdoc.CreateElem ent("eOnLineRes ource","Default NSDickster")
      >
      eOnlineResource .SetAttribute(" href",
      "http://www.w3c.org/1999/xlink", "theValue")
      >
      xdoc.FirstChild .AppendChild(eO nlineResource)
      >
      -------------------------------------------------------------------------------------------------------------
      >
      The prefix will be in the XML.
      >
      Dickster
      >
      >

      Comment

      • Martin Honnen

        #4
        Re: SetAttribute xlink:href



        jvanulden wrote:
        I am having difficulty figuring out how to create an XmlElement and giving
        it an attribute that requires a namespace. Here is what I have so far which
        throws an exception because you can't have a : in an attribute name???
        >
        XmlElement eOnlineResource = m_context.Creat eElement("Onlin eResource");
        >
        eOnlineResource .SetAttribute(" xlink:href", "http://www.w3c.org/1999/xlink",
        sldUrl);
        This should help:

        XmlDocument xmlDocument = new XmlDocument();
        XmlElement eOnlineResource =
        xmlDocument.Cre ateElement("Onl ineResource");
        XmlAttribute xlinkHref = xmlDocument.Cre ateAttribute("x link",
        "href", "http://www.w3.org/1999/xlink");
        xlinkHref.Value = "http://example.com/example";
        eOnlineResource .SetAttributeNo de(xlinkHref);

        For the attribute value you obviously want your sldUrl then instead of
        the example.com URL the example shows.



        --

        Martin Honnen --- MVP XML
        http://JavaScript.FAQTs.com/

        Comment

        • jvanulden

          #5
          Re: SetAttribute xlink:href

          Thanks Martin, that worked!

          "Martin Honnen" wrote:
          >
          >
          jvanulden wrote:
          >
          I am having difficulty figuring out how to create an XmlElement and giving
          it an attribute that requires a namespace. Here is what I have so far which
          throws an exception because you can't have a : in an attribute name???

          XmlElement eOnlineResource = m_context.Creat eElement("Onlin eResource");

          eOnlineResource .SetAttribute(" xlink:href", "http://www.w3c.org/1999/xlink",
          sldUrl);
          >
          This should help:
          >
          XmlDocument xmlDocument = new XmlDocument();
          XmlElement eOnlineResource =
          xmlDocument.Cre ateElement("Onl ineResource");
          XmlAttribute xlinkHref = xmlDocument.Cre ateAttribute("x link",
          "href", "http://www.w3.org/1999/xlink");
          xlinkHref.Value = "http://example.com/example";
          eOnlineResource .SetAttributeNo de(xlinkHref);
          >
          For the attribute value you obviously want your sldUrl then instead of
          the example.com URL the example shows.
          >
          >
          >
          --
          >
          Martin Honnen --- MVP XML
          http://JavaScript.FAQTs.com/
          >

          Comment

          Working...