Results 1 to 9 of 9

Thread: XML Namespaces and ASP

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    London
    Posts
    58

    XML Namespaces and ASP

    I have the following code:

    Code:
    strDesc = "Stuff"
    
    set xmldoc = Server.CreateObject("msxml2.DOMDocument")
    
    set root = xmldoc.createNode("element","file","")
    xmldoc.appendChild(root)
    set root = xmldoc.documentElement
    
    set newNode = xmldoc.createNode("element", "info", "")
    newNode.Text = strDesc
    root.appendChild newNode
    which produces the following XML:

    Code:
    <file>
      <info>Stuff</info>
    </file>
    what I want to produce is the following:

    Code:
    <xs:file>
      <xs:info>Stuff</xs:info>
    </xs:file>
    i.e. the same with an xs namespace.

    How do I go about doing this? If I just add xs: to my tag names I get an error saying "undeclared namespace".

    I have tried adding the following line but I still get the same error:

    Code:
    xmldoc.setProperty "SelectionNamespaces", "xmlns:xs='http://www.w3.org/1999/XSL/Transform'"
    Any help would be much appreciated.

    RKW

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: XML Namespaces and ASP

    Use the createElementNS method to create the elements. You also need to set some property of the XML serializer so that it will use xs as the namespace prefix for whatever namespace you use.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    London
    Posts
    58

    Re: XML Namespaces and ASP

    Thanks for your help.
    I tried changing the createNode line to
    Code:
    set root = xmldoc.createElementNS("http://test.com","xs:file")
    But now I am getiing the message "Object doesn't support this property or method 'createElementNS'"

    What do you mean by the "XML serializer"? I guess that this is what I am missing.

    Thank you once again.
    RKW

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: XML Namespaces and ASP

    Hmm - perhaps an outdated version of MSXML? Or MSHTML? Hmm...
    Mind you, you'd only put "file", not "xs:file" as the element name.

    As for XML serializer, well, what actually "produces" your result XML? The function calls create an in-memory representation. Somewhere there must be a serializer that turns that into actual XML.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    London
    Posts
    58

    Re: XML Namespaces and ASP

    Sorry to be a pain, but if I just put "file" I get the same error message and how would it then know that I wanted to have "xs" as my namespace?

    Can anyone see where I am going wrong? I am obviously missing something.

    RKW

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: XML Namespaces and ASP

    Well, you would do this:
    node = document.createElementNS("scheme:my_namespace_uri", "file");

    And then there must be a place where you write the object tree into XML data. There you would have to configure it to map the namespace "scheme:my_namespace_uri" to the abbreviation "xs".
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    London
    Posts
    58

    Re: XML Namespaces and ASP

    I have returned to this problem and have still not solved it.

    I keep getting the error "Object doesn't support this property or method: 'createElementNS'" whatever I do.

    I am using MSXML 4.2. Can anybody help? Is there a way of doing this without using createElementNS?

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: XML Namespaces and ASP

    *checks*

    *re-checks*

    *blinks*

    I can't believe it!

    OK, the situation is, apparently, like this: MSXML sucks.

    In other words, all of MSDN contains a single mention of createElementNS, and that's in an article about namespaces. Neither the IE object model reference, nor the .Net DOM reference, nor the MSXML reference contain any mention of this method. It seems to be completely unsupported. The .Net DOM provides an overload of the regular createElement method that does what the NS variant should do, apparently. However, the documentation is completely faulty and if this really what the method does, then it's completely broken.

    Given this problem, you might want to look into an alternative to MSXML.
    http://xml.apache.org/xerces-c/
    Xerces-C++ has a COM wrapper that allows it to be used from VB. I'm afraid, however, that you'll have to build the library yourself in order to use it.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    London
    Posts
    58

    Re: XML Namespaces and ASP

    Changing parser is not really an option, but thanks anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width