主要内容

このページの翻訳は最新ではありませ。

XMLREAD.

XMLドキュメントドキュメントを読み取っ,ドキュメントオブジェクトモデルノードを返す

说明

domnode = xmlread(文件名的)は,指定されたxmlファイルを読み取って,そのそのドキュメントを表すドキュメントオブジェクトモデルモデルDomnode.を返します。

XMLREAD.のの取り扱いに,java®API for XML Processing (JAXP) を使用する必要があります。詳細については、https://docs.oracle.com/javase/7/docs/apiを参照してください。

domnode = xmlread(文件名,'allowdoctype',tf)は、DOCTYPE 宣言が許可されているかどうかも指定します。TF.错误的のの合,doctype宣言宣言が含まれるれる入ファイルを読み取るとになりますなりなりなりますなりなりなりなりなりますなりなりなりなります场なりなりなりなりなり场场XMLREAD.は、XML ファイルの出力Domnode.を返します。TF.の既定値はtrueです。

すべて折りたたむ

サンプルXMLファイルファイルの内容を调べて,そのXMLファイルをドキュメントオブジェクト(DOM)ノードノード読み取ります。

ファイルsample.xml.の内容を表示します。

samplexmlfile ='sample.xml';类型(SamplexMlFile)
< productinfo > < matlabrelease>R2012a Example Manager internal ApplicationIcon.DEMOS    com.mathworks.xwidgets.ExampleManager.showViewer  ApplicationIcon.DEMOS   

XMLファイルをDOMノードに読み取ります。

domnode = xmlread(samplexmlfile);

XML关关を制作し,XMLファイルをMATLAB®构造体に読み取っから,サンプルXMLファイルをmatlabワークスペースにます。

关节有关部parsexml.を作物成するは,このコードをコピーしてmファイルparsexml.m.に贴り付けるか,この例ででられいるparsexml.m.关联用します。关键词parsexml.はXMLファイルのデータを解析し,フィールド姓名属性Data,および孩子们をもつ MATLAB 構造体配列に格納します。

类型('parsexml.m'的)
功能Thestuct = ParseXML(文件名)%ParseXML将XML文件转换为Matlab结构。尝试树= XMLREAD(文件名);捕获错误('无法读取XML文件%s。',filename);END%对子节点进行复发。这可能遇到了非常深入的树木的问题。尝试thestuct = parsechildnodes(树);捕获错误('无法解析XML文件%s。',filename);exp%-----本地函数parseChildnodes -----函数子= ParseChildNodes(heode)%在节点儿童复发。儿童= [];如果bonode.haschildnodes shildnodes = whenode.getChildNodes; numChildNodes = childNodes.getLength; allocCell = cell(1, numChildNodes); children = struct( ... 'Name', allocCell, 'Attributes', allocCell, ... 'Data', allocCell, 'Children', allocCell); for count = 1:numChildNodes theChild = childNodes.item(count-1); children(count) = makeStructFromNode(theChild); end end % ----- Local function MAKESTRUCTFROMNODE ----- function nodeStruct = makeStructFromNode(theNode) % Create structure of node info. nodeStruct = struct( ... 'Name', char(theNode.getNodeName), ... 'Attributes', parseAttributes(theNode), ... 'Data', '', ... 'Children', parseChildNodes(theNode)); if any(strcmp(methods(theNode), 'getData')) nodeStruct.Data = char(theNode.getData); else nodeStruct.Data = ''; end % ----- Local function PARSEATTRIBUTES ----- function attributes = parseAttributes(theNode) % Create attributes structure. attributes = []; if theNode.hasAttributes theAttributes = theNode.getAttributes; numAttributes = theAttributes.getLength; allocCell = cell(1, numAttributes); attributes = struct('Name', allocCell, 'Value', ... allocCell); for count = 1:numAttributes attrib = theAttributes.item(count-1); attributes(count).Name = char(attrib.getName); attributes(count).Value = char(attrib.getValue); end end

サンプルファイルinfo.xml.を解析ししmatlab构造体にするに,关联parsexml.を使使し。

samplexmlfile ='info.xml';mlstruct = parsexml(Samplexmlfile)
mlstruct =.结构与字段:名称:'ProductInfo'属性:[1x2结构]数据:''儿童:[1x13结构]

入力数

すべて折りたたむ

ファイル名。ローカルファイル名またはurlを含む,文章ベクトルまたは字符串スカラーとして指定ます。

データ型:char|细绳

R2006a より前に導入