3 Replies Latest reply: Oct 14, 2013 8:58 AM by Aegis Kleais RSS

    Create i:nil XML Attribute

    rhpt Community Member

      I need to create an XML Document with an element that requires the attribute i:nil=true. I've tried <cfset StructInsert(mydoc.employee.name.XmlAttributes, "i:nil", "true")>, but it returns the error "The right hand side of the assignment is not of type XML Node".

       

      What I want is to create an element like this: <name i:nil="true"/>

       

      Any help would be greatly appreciated.

        • 1. Re: Create i:nil XML Attribute
          Aegis Kleais Community Member

          What does this produce?

           

          <cfdump var="#isStruct( mydoc.employee.name.xmlAttributes )#" />

           

          If it's Yes/True, I think the problem here has to do with you attempting to set a key with a value that is not permitted.  Variables cannot have special characters like ':' in them.  To quickly test this, change 'i:nil' to 'i_nil' since underscores are permitted.

           

          The xmlAttributes() method returns back a structure of key/value pairs.

           

          Is it valid for an XML node to look like:

           

          <user lastname="smith" firstname="john" i:nil="true" /> ?

           

          Not sure that's allowed.

           

          If you're attempting to use namespaces, those are placed onto the root element <user> not its attributes.  Like:

           

          <i:user lastname="smith" firstname="john" />

          • 2. Re: Create i:nil XML Attribute
            rhpt Community Member

            Figured this out thank to Stackoverflow. Simply use a direct assignment.

             

            <cfset mydoc.employee.name.xmlAttributes["i:nil"] = true>

            • 3. Re: Create i:nil XML Attribute
              Aegis Kleais Community Member

              Happy you got it rolling, but I gotta say I'm very surprised here.

               

              To my knowledge the xmlAttributes() function returns a structure, which is just a series of name/value pairs.  I guess I'm so used to keeping special characters outside of my variable names that I never really tried to set one with a colon in it.  Come to think of it, I think CF is more concerned about the FIRST character of the variable name than subsequent ones.  Like, the variable couldn't be called ':nil', because it began with the colon, but the colon could exist as a subsequent character in the variable name.

               

              Good to know.