hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

XAttribute default namespace

Last post 02-09-2010, 5:54 by dwo. 3 replies.
Sort Posts: Previous Next
  •  02-06-2010, 2:33 13033

    XAttribute default namespace

    I'm using the Xml.Linq XElement/XAttribute functions and am trying to specify the default namespace for an element.   I believe I'm following the documentation properly (

    http://msdn.microsoft.com/en-us/library/bb387075.aspx)  but get an error complaining that the type system was looking for an XName rather than a string.   The code is:

     

    <SPAN style="COLOR: #1f497d; mso-bidi-font-family: 'Times New Roman'"><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>

    let</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT color=#000000 size=2 face=Consolas> gptg : XNamespace = XNamespace.op_Implicit( </FONT></FONT><FONT color=#800000 size=2 face=Consolas><FONT color=#800000 size=2 face=Consolas><FONT color=#800000 size=2 face=Consolas>"gptg:PMSA:gptg.net"</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas><FONT color=#000000>)</FONT></FONT></FONT>

    <FONT size=2 face=Consolas><FONT size=2 face=Consolas><FONT color=#000000>makeBaseDocumentX (docName : string) =</FONT>

    </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>   let</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> elt = </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>new</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> XElement(gptg + docName,

    </FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>                           new</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> XAttribute(</FONT></FONT><FONT color=#800000 size=2 face=Consolas><FONT color=#800000 size=2 face=Consolas><FONT color=#800000 size=2 face=Consolas>"xmlns"</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>, </FONT></FONT><FONT color=#800000 size=2 face=Consolas><FONT color=#800000 size=2 face=Consolas><FONT color=#800000 size=2 face=Consolas>"gptg:PMSA:gptg.net"</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>))

       elt

    </FONT></FONT></SPAN>

    When I use C# (with appropriate modifications), the code seems to work just fine.   Is there something I'm doing wrong, or is this an error in F#?

     

    Thanks,

     --Don

  •  02-06-2010, 2:37 13034 in reply to 13033

    Re: XAttribute default namespace

    Arghh...  :-)

    My attempt to insert the code appears to have generated garbage.  I'll try again without the editor help.

    let gptg : XNamespace = XNamespace.op_Implicit( "gptg:PMSA:gptg.net")

    let makeBaseDocument (docName : string) =

       let elt = new XElement(gptg + docName,

                              new XAttribute("xmlns", "gptg:PMSA:gptg.net"))

       elt

  •  02-06-2010, 5:56 13036 in reply to 13033

    Re: XAttribute default namespace

    dwo:
    When I use C# (with appropriate modifications), the code seems to work just fine.
    Because there's yet another hidden implicit conversion ;) .

    new XAttribute(XName.op_Implicit "xmlns", "gptg:PMSA:gptg.net")

    PS: Have a look at the conversion operator: http://cs.hubfs.net/forums/thread/11111.aspx
  •  02-09-2010, 5:54 13056 in reply to 13036

    Re: XAttribute default namespace

    Thanks - that should have been my first guess. :-)

    --Don

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems