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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)