Results 1 to 5 of 5

Thread: Generating XML

  1. #1

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Generating XML

    Hi

    This is a weird one. I'm using a reference to msxml3.dll and the following code to generate an xml file:

    Code:
            'Create "message" node
            Set xmln_message = xmlDoc.createNode(XMLELEMTYPE_TEXT, "message", "")
            xmlDoc.appendChild xmln_message
        
            Set xmlAttribute = xmlDoc.createAttribute("xmlns")
            xmlAttribute.Value = "http://www.origoservices.com"
            xmln_message.Attributes.setNamedItem xmlAttribute
                
            Set xmlAttribute = xmlDoc.createAttribute("xmlns:fp")
            xmlAttribute.Value = "http://www.friendsprovident.com"
            xmln_message.Attributes.setNamedItem xmlAttribute
        
            Set xmlAttribute = xmlDoc.createAttribute("xmlns:origo")
            xmlAttribute.Value = "http://www.origoservices.com"
            xmln_message.Attributes.setNamedItem xmlAttribute
        
            Set xmlAttribute = xmlDoc.createAttribute("xmlns:x")
            xmlAttribute.Value = "http://www.origoservices.com"
            xmln_message.Attributes.setNamedItem xmlAttribute
        
            Set xmlAttribute = xmlDoc.createAttribute("xmlns:xsi")
            xmlAttribute.Value = "http://www.w3.org/2001/XMLSchema-instance"
            xmln_message.Attributes.setNamedItem xmlAttribute
            
            'Create "m_control" node
            Set xmln_mcontrol = xmlDoc.createNode(XMLELEMTYPE_TEXT, "m_control", "")
            xmln_message.appendChild xmln_mcontrol
    ...etc etc to create the other nodes in the page

    all the objects have been properly instantiated etc and all the nodes with child nodes have their own object variable. The problem is that the "xmlns" attribute although only added to the "message" node, appears on all of the child nodes of "message" as well, im currently using a workaround by using a replace function on the generated xml to remove the unneeded "xmlns" attributes but obviously i would prefer to avoid it happening at all. Strangely it does not do the same with the other attributes of the "message" node. any help would be much appreciated with this one!
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  2. #2

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: Generating XML

    anyone?
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Generating XML

    Please don't bump your threads.

    When I use that xml code I get a file that looks like this

    <message xmlns="http://www.origoservices.com" xmlns:fp="http://www.friendsprovident.com" xmlns:origo="http://www.origoservices.com" xmlns:x="http://www.origoservices.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><m_control xmlns=""/></message>

    Is it the xmlns part like the highlighted one that you don't want? If so then just change your CreateAttribute statements form, for example

    xmlDoc.createAttribute("xmlns:fp")

    to

    xmlDoc.createAttribute("fp")

  4. #4

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: Generating XML

    My apologies for the bump, but no, when i create nodes as childnodes of "message" they have a blank attribute so they appear as:

    <childnode xmlns="">
    stuff
    </childnode>

    as you can see on your post on the mcontrol node
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Generating XML

    If I understand correctly what you want, it's because you aren't adding a value. In this case I've added "blah"

    Set xmln_mcontrol = xmlDoc.createNode(XMLELEMTYPE_TEXT, "m_control", "blah")

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