MATLAB - XML 查找兄弟元素
MATLAB - XML Find sibling element
我有以下 XML 结构:
<LMS>
<StressGradientCorrection>
<Gradients>
<Gradient>
<Curve>
<Point>
<NormalizedGradient Value="0.01" />
<ReductionFactor Value="1" />
</Point>
<Point>
<NormalizedGradient Value="0.1" />
<ReductionFactor Value="1" />
</Point>
<Point>
<NormalizedGradient Value="1" />
<ReductionFactor Value="1" />
</Point>
<Point>
<NormalizedGradient Value="10" />
<ReductionFactor Value="1" />
</Point>
</Curve>
</Gradient>
</Gradients>
</StressGradientCorrection>
</LMS>
我需要根据同一个 <Point>
中 <NormalizedGadient>
的值更改每个 <ReductionFactor>
的值。到目前为止,我只能根据元素的属性(例如名称或值)来区分元素,但在这里我不能。如何根据兄弟元素的值区分元素?
这是开始的一段代码:
clear all
close all
clc
% Import the XPath classes
import javax.xml.xpath.*
% Construct the DOM.
doc = xmlread('SGC_EXAMPLE.xml');
% Creating an xPath
factory = javax.xml.xpath.XPathFactory.newInstance();
xpath = factory.newXPath();
Path = xpath.compile('/LMS/StressGradientCorrection/Gradients/Gradient/Curve/Point/NormalizedGradient[@Value="0.01"]');
List = Path.evaluate(doc, XPathConstants.NODESET);
Sibling = List.item(0);
% YOUR PROPOSAL HERE
MyNewlyFoundVariable.setAttribute('Value','5')
xmlwrite('Final.xml',doc);
到目前为止我只知道如何根据它的值找到兄弟姐妹。
您可以像这样找到以下兄弟姐妹:
/LMS/StressGradientCorrection/Gradients/Gradient/Curve/Point/NormalizedGradient[@Value="0.01"]/following-sibling::ReductionFactor/@Value
我有以下 XML 结构:
<LMS>
<StressGradientCorrection>
<Gradients>
<Gradient>
<Curve>
<Point>
<NormalizedGradient Value="0.01" />
<ReductionFactor Value="1" />
</Point>
<Point>
<NormalizedGradient Value="0.1" />
<ReductionFactor Value="1" />
</Point>
<Point>
<NormalizedGradient Value="1" />
<ReductionFactor Value="1" />
</Point>
<Point>
<NormalizedGradient Value="10" />
<ReductionFactor Value="1" />
</Point>
</Curve>
</Gradient>
</Gradients>
</StressGradientCorrection>
</LMS>
我需要根据同一个 <Point>
中 <NormalizedGadient>
的值更改每个 <ReductionFactor>
的值。到目前为止,我只能根据元素的属性(例如名称或值)来区分元素,但在这里我不能。如何根据兄弟元素的值区分元素?
这是开始的一段代码:
clear all
close all
clc
% Import the XPath classes
import javax.xml.xpath.*
% Construct the DOM.
doc = xmlread('SGC_EXAMPLE.xml');
% Creating an xPath
factory = javax.xml.xpath.XPathFactory.newInstance();
xpath = factory.newXPath();
Path = xpath.compile('/LMS/StressGradientCorrection/Gradients/Gradient/Curve/Point/NormalizedGradient[@Value="0.01"]');
List = Path.evaluate(doc, XPathConstants.NODESET);
Sibling = List.item(0);
% YOUR PROPOSAL HERE
MyNewlyFoundVariable.setAttribute('Value','5')
xmlwrite('Final.xml',doc);
到目前为止我只知道如何根据它的值找到兄弟姐妹。
您可以像这样找到以下兄弟姐妹:
/LMS/StressGradientCorrection/Gradients/Gradient/Curve/Point/NormalizedGradient[@Value="0.01"]/following-sibling::ReductionFactor/@Value