/ / MATLAB - Élément frère XML Find - xml, matlab, xpath, frères et sœurs

MATLAB - XML ​​Rechercher élément frère - xml, matlab, xpath, frères et sœurs

J'ai la structure XML suivante:

<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>

Je dois changer la valeur de chacun <ReductionFactor>, en fonction de la valeur du <NormalizedGadient> dans le même <Point>. Jusqu'à présent, je peux distinguer un élément uniquement en fonction de ses attributs, comme le nom ou la valeur, mais ici je ne peux pas. Comment puis-je distinguer un élément, en fonction de la valeur d'un élément frère?

Voici le morceau de code de départ:

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);

Jusqu'à présent, je sais juste comment trouver le frère en fonction de sa valeur.

Réponses:

2 pour la réponse № 1

Vous pouvez trouver le frère suivant comme ceci:

/LMS/StressGradientCorrection/Gradients/Gradient/Curve/Point/NormalizedGradient[@Value="0.01"]/following-sibling::ReductionFactor/@Value