• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Create i:nil XML Attribute

Explorer ,
Oct 11, 2013 Oct 11, 2013

Copy link to clipboard

Copied

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.

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 13, 2013 Oct 13, 2013

Copy link to clipboard

Copied

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" />

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 14, 2013 Oct 14, 2013

Copy link to clipboard

Copied

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

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 14, 2013 Oct 14, 2013

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation