addAttributeXML
Below is a demonstration of the features of the addAttributeXML function
Contents
clear; close all; clc;
Syntax
[domNode]=addAttributeXML(domNode,elementNode,attrName,attrValue);
Description
This function adds a single attribute defined by attrName and attrValue to the XML defined by the XML object domNode. The attribute value can be a character/string or numerical data. Vector valued data is transformed to comma separated values e.g. 1:3 will become 1, 2, 3. Integer values will remain integer type. For non-integer numberical data exponential notation is used e.g. pi becomes 3.1415927e+00.
Examples
Defining an XML with elements and attributes
The below example codes this XML section:
febio_spec Material id="1" type="Ogden" c>2</c /material /Material /febio_spec
Initialize XML object
domNode = com.mathworks.xml.XMLUtils.createDocument('febio_spec'); rootNode=domNode.getElementsByTagName('febio_spec').item(0);
Add elements
Main element
elementName='Material'; elementValue=[]; [domNode,elementNode,~]=addElementXML(domNode,rootNode,elementName,elementValue); %A child element of the main element elementName='material'; elementValue=[]; [domNode,subElementNode,~]=addElementXML(domNode,elementNode,elementName,elementValue); %A child element of the child element elementName='c'; elementValue=2; [domNode,subSubElementNode,~]=addElementXML(domNode,subElementNode,elementName,elementValue);
Defining an element attribute
attrName='id'; %Attrivute name attrValue=1; %Attribute value [domNode]=addAttributeXML(domNode,subElementNode,attrName,attrValue); attrName='type'; %Attrivute name attrValue='Ogden'; %Attribute value [domNode]=addAttributeXML(domNode,subElementNode,attrName,attrValue);
View XML
xmlView(domNode);
GIBBON www.gibboncode.org
Kevin Mattheus Moerman, [email protected]
GIBBON footer text
License: https://github.com/gibbonCode/GIBBON/blob/master/LICENSE
GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for image segmentation, image-based modeling, meshing, and finite element analysis.
Copyright (C) 2019 Kevin Mattheus Moerman
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.