eateCDATASection() - Web APIs - MDN - Mozilla
Maybe your like
- Skip to main content
- Skip to search
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
- Learn more
- See full compatibility
- Report feedback
createCDATASection() creates a new CDATA section node, and returns it.
In this article
- Syntax
- Examples
- Notes
- Specifications
- Browser compatibility
Syntax
jscreateCDATASection(data)Parameters
dataA string containing the data to be added to the CDATA Section.
Return value
A CDATA Section node.
Examples
jsconst doc = new DOMParser().parseFromString("<xml></xml>", "application/xml"); const cdata = doc.createCDATASection("Some <CDATA> data & then some"); doc.querySelector("xml").appendChild(cdata); console.log(new XMLSerializer().serializeToString(doc)); // Displays: <xml><![CDATA[Some <CDATA> data & then some]]></xml>Notes
- This will only work with XML, not HTML documents (as HTML documents do not support CDATA sections); attempting it on an HTML document will throw NOT_SUPPORTED_ERR.
- Will throw a NS_ERROR_DOM_INVALID_CHARACTER_ERR exception if one tries to submit the closing CDATA sequence (]]>) as part of the data, so unescaped user-provided data cannot be safely used without this method getting this exception (createTextNode() can often be used in its place).
Specifications
| Specification |
|---|
| DOM# ref-for-dom-document-createcomment① |
Browser compatibility
Help improve MDN
Was this page helpful to you? Yes No Learn how to contributeThis page was last modified on Oct 16, 2024 by MDN contributors.
View this page on GitHub • Report a problem with this content Filter sidebar- Document Object Model (DOM)
- Document
- Constructor
- Document()
- Instance properties
- activeElement
- activeViewTransition
- adoptedStyleSheets
- alinkColor Deprecated
- all Deprecated
- anchors Deprecated
- applets Deprecated
- bgColor Deprecated
- body
- characterSet
- childElementCount
- children
- compatMode
- contentType
- cookie
- currentScript
- defaultView
- designMode
- dir
- doctype
- documentElement
- documentURI
- domain Deprecated
- embeds
- featurePolicy Experimental
- fgColor Deprecated
- firstElementChild
- fonts
- forms
- fragmentDirective
- fullscreen Deprecated
- fullscreenElement
- fullscreenEnabled
- head
- hidden
- images
- implementation
- lastElementChild
- lastModified
- lastStyleSheetSet Non-standard Deprecated
- linkColor Deprecated
- links
- location
- pictureInPictureElement
- pictureInPictureEnabled
- plugins
- pointerLockElement
- preferredStyleSheetSet Non-standard Deprecated
- prerendering Experimental
- readyState
- referrer
- rootElement Deprecated
- scripts
- scrollingElement
- selectedStyleSheetSet Non-standard Deprecated
- styleSheets
- styleSheetSets Non-standard Deprecated
- timeline
- title
- URL
- visibilityState
- vlinkColor Deprecated
- xmlEncoding Deprecated
- xmlVersion Deprecated
- Static methods
- parseHTML() Experimental
- parseHTMLUnsafe()
- Instance methods
- adoptNode()
- append()
- ariaNotify() Experimental Non-standard
- browsingTopics() Non-standard Deprecated
- caretPositionFromPoint()
- caretRangeFromPoint() Non-standard
- clear() Deprecated
- close()
- createAttribute()
- createAttributeNS()
- createCDATASection()
- createComment()
- createDocumentFragment()
- createElement()
- createElementNS()
- createEvent() Deprecated
- createExpression()
- createNodeIterator()
- createNSResolver() Deprecated
- createProcessingInstruction()
- createRange()
- createTextNode()
- createTouch() Non-standard Deprecated
- createTouchList() Non-standard Deprecated
- createTreeWalker()
- elementFromPoint()
- elementsFromPoint()
- enableStyleSheetsForSet() Non-standard Deprecated
- evaluate()
- execCommand() Deprecated
- exitFullscreen()
- exitPictureInPicture()
- exitPointerLock()
- getAnimations()
- getElementById()
- getElementsByClassName()
- getElementsByName()
- getElementsByTagName()
- getElementsByTagNameNS()
- getSelection()
- hasFocus()
- hasPrivateToken() Experimental
- hasRedemptionRecord() Experimental
- hasStorageAccess()
- hasUnpartitionedCookieAccess()
- importNode()
- moveBefore()
- mozSetImageElement() Non-standard
- open()
- prepend()
- queryCommandEnabled() Non-standard Deprecated
- queryCommandState() Non-standard Deprecated
- queryCommandSupported() Non-standard Deprecated
- querySelector()
- querySelectorAll()
- releaseCapture() Non-standard
- replaceChildren()
- requestStorageAccess()
- requestStorageAccessFor() Experimental
- startViewTransition()
- write() Deprecated
- writeln() Deprecated
- Events
- afterscriptexecute Non-standard Deprecated
- beforescriptexecute Non-standard Deprecated
- DOMContentLoaded
- fullscreenchange
- fullscreenerror
- pointerlockchange
- pointerlockerror
- prerenderingchange Experimental
- readystatechange
- scroll
- scrollend
- scrollsnapchange Experimental
- scrollsnapchanging Experimental
- securitypolicyviolation
- selectionchange
- visibilitychange
- Inheritance
- Node
- EventTarget
- Related pages for DOM
- AbortController
- AbortSignal
- AbstractRange
- Attr
- CDATASection
- CharacterData
- Comment
- CustomEvent
- DOMError Deprecated
- DOMException
- DOMImplementation
- DOMParser
- DOMTokenList
- DocumentFragment
- DocumentType
- Element
- Event
- EventTarget
- HTMLCollection
- MutationObserver
- MutationRecord
- NamedNodeMap
- Node
- NodeIterator
- NodeList
- ProcessingInstruction
- QuotaExceededError Experimental
- Range
- ShadowRoot
- StaticRange
- Text
- TreeWalker
- XMLDocument
- XPathEvaluator
- XPathExpression
- XPathResult
- XSLTProcessor
- Guides
- Anatomy of the DOM
- Attribute reflection
- Selection and traversal on the DOM tree
- Building and updating the DOM tree
- Working with events
Tag » Add Cdata Tag In Xml
-
How Do I Add CDATA To An Xml File? - Stack Overflow
-
XML CDATA | How CDATA Works In XML With Examples - EduCBA
-
How To Programmatically Add A CDATA Section To An XML Document ...
-
What Does Node In A XML Document | Our Code World
-
Adding CDATA Section To XML Element - ⋮IWConnect
-
Adding Tag
-
How To Add CData In The XML Nodes Using Dataweave 2.0?
-
Working With CDATA | Functional Testing - SoapUI
-
XML - CDATA Sections - Tutorialspoint
-
XmlDocument.CreateCDataSection(String) Method (System.Xml)
-
How To Stop An XML Map From Adding !CDATA Elements For ... - IBM
-
XMLNSC: Working With CData - IBM
-
XML CDATA - W3resource
-
Add CDATA To SimpleXMLElement Without Create A Custom Class