matlab.io.xml.dom.DocumentFragment Class
Namespace: matlab.io.xml.dom
Description
Use an object of the matlab.io.xml.dom.DocumentFragment
class as a
container for a group of document nodes. Appending a document fragment to another node appends
the children of the fragment but not the fragment itself. Similarly, inserting a fragment
inserts the children but not the fragment. A fragment does not have to be well-formed XML. For
example, a fragment can contain multiple top-level nodes or a single text node.
The matlab.io.xml.dom.DocumentFragment
class is a handle
class.
Class Attributes
ConstructOnLoad | true |
HandleCompatible | true |
For information on class attributes, see Class Attributes.
Creation
You can create a matlab.io.xml.dom.DocumentFragment
object by using the
createDocumentFragment
method of a matlab.io.xml.dom.Document
object.
Properties
Text content of this document fragment, specified as a character vector or string scalar. This property contains the concatenated textual content of the children of this fragment.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
Methods
appendChild |
|
child |
|
cloneNode |
|
compareDocumentPosition |
|
getAttributes |
|
getChildNodes |
|
getChildren |
|
getFirstChild | child = getFirstChild(thisFragment) returns the first child
of this fragment. |
getLastChild | child = getLastChild(thisFragment) returns the last child of
this fragment. |
getLength |
|
getLocalName |
|
getNamespaceURI |
|
getNextSibling |
|
getNodeName |
|
getNodeType |
This method provides compatibility with existing MATLAB® code that is based on the W3C XML DOM standard. For new
MATLAB code, use import matlab.io.xml.dom.* d = Document('book'); frag= createDocumentFragment(d); if isa(frag,'matlab.io.xml.dom.DocumentFragment') fprintf('This is an document fragment.\n'); end |
getNodeValue |
|
getOwnerDocument |
|
getParentNode | parent = getParentNode(thisFragment) returns an empty node
object because document fragments do not have parents. |
getPrefix |
|
getPreviousSibling |
|
getTextContent | getTextContent(thisFragment) returns the text content of
this fragment. If this fragment has children, the method returns the concatenated
text content of the children. |
hasAttributes |
|
hasChildNodes |
|
insertBefore |
If
|
isDefaultNamespace |
|
isEqualNode |
This method tests for equality of nodes, not whether the nodes
are handles to the same object. To test for sameness, use the
Nodes that are the same are also equal, but nodes that are equal are not necessarily the same. |
isSameNode |
|
item |
|
lookupNamespaceURI |
|
lookupPrefix |
|
normalize |
|
removeChild |
|
replaceChild |
|
setNodeValue |
|
setPrefix |
|
setTextContent |
Specify |
Examples
Suppose that your application creates chapters and that the number of chapters is determined at run time. You can write a function, such as the createChapters
function, defined at the end of this example, to create a specified number of chapter elements and return them as a document fragment.
Create a document that has a root element named book
.
import matlab.io.xml.dom.* doc = Document("book"); docElemRoot = getDocumentElement(doc);
Call the function createChapters
to return three chapters as a matlab.io.xml.dom.DocumentFragment
object. Append the fragment to the document.
docFrag = createChapters(doc,3); appendChild(docElemRoot,docFrag);
Write the document to the file book.xml
.
xmlFileName = "book.xml";
writer = matlab.io.xml.dom.DOMWriter;
writeToFile(writer,doc,xmlFileName);
Display the resulting XML.
type(xmlFileName);
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><book><chapter>Chapter 1</chapter><chapter>Chapter 2</chapter><chapter>Chapter 3</chapter></book>
The createChapters
Function
The function createChapters
returns a DocumentFragment
object that contains the specified number of chapter elements.
function docFrag = createChapters(doc,n) docFrag = createDocumentFragment(doc); for i=1:n chapter = createElement(doc,"chapter"); appendChild(chapter,createTextNode(doc,sprintf("Chapter %d",i))); appendChild(docFrag,chapter); end end
Version History
Introduced in R2021a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)