I have a XML file template like this that comes from some IC chips, I want to be able to store each Pins Test type datas as an array so later I can draw it on a cartesian graph.
The data structure is like this:
<NUMBER></NUMBER> is name of the IC’s particular pin
<Curve Count=""> is number of tests done to a pin
<Type></Type> is type of test
and there are some voltage values and current values that I have to put in an array so I can use it later.
Anyway! My question is how can I get these values? I do not ask for a direct answer (but it is appriciated) but some guide that make me to find the thread is really appriciated.
EDIT: If somone kindly give me a code to have 3 voltage and 3 current values from A1 I can easily get the idea and continue myself.
This XML looks likes this:
<?xml version="1.0" encoding="utf-8"?>
<Document>
<Device>NEC555</Device>
<Pins Count="3">
<Pin>
<Number>A1</Number>
<Curves Count ="3">
<Curve>
<Type>PreStress</Type>
<VIPairs Count="3">
<VIPair>
<Voltage>-2</Voltage>
<Current>-0.003</Current>
</VIPair>
<VIPair>
<Voltage>-1</Voltage>
<Current>-0.002</Current>
</VIPair>
<VIPair>
<Voltage>-0</Voltage>
<Current>-0.001</Current>
</VIPair>
</VIPairs>
</Curve>
<Curve>
<Type>PreFail</Type>
<VIPairs Count="3">
<VIPair>
<Voltage>-2</Voltage>
<Current>-0.003</Current>
</VIPair>
<VIPair>
<Voltage>-1</Voltage>
<Current>-0.002</Current>
</VIPair>
<VIPair>
<Voltage>-0</Voltage>
<Current>-0.001</Current>
</VIPair>
</VIPairs>
</Curve>
<Curve>
<Type>PostFail</Type>
<VIPairs Count="0">
</VIPairs>
</Curve>
</Curves>
</Pin>
<Pin>
<Number>B1</Number>
<Curves Count ="3">
<Curve>
<Type>PreStress</Type>
<VIPairs Count="3">
<VIPair>
<Voltage>-3</Voltage>
<Current>-0.005</Current>
</VIPair>
<VIPair>
<Voltage>-1</Voltage>
<Current>-0.002</Current>
</VIPair>
<VIPair>
<Voltage>-0</Voltage>
<Current>-0.001</Current>
</VIPair>
</VIPairs>
</Curve>
<Curve>
<Type>PreFail</Type>
<VIPairs Count="3">
<VIPair>
<Voltage>-3</Voltage>
<Current>-0.003</Current>
</VIPair>
<VIPair>
<Voltage>-1</Voltage>
<Current>-0.002</Current>
</VIPair>
<VIPair>
<Voltage>-0</Voltage>
<Current>-0.001</Current>
</VIPair>
</VIPairs>
</Curve>
<Curve>
<Type>PostFail</Type>
<VIPairs Count="0">
</VIPairs>
</Curve>
</Curves>
</Pin>
</Pins>
</Document>
Much as I like using LINQ and
XDocument, this is a case where XPath is simpler.Given your XML, this XPath finds all of the
VIPairelements under aPinelement with a givenNumberand under aCurveelement with a givenType:Using an
XmlDocument, the code to get your three voltage and current values would look like this:Using an XDocument, the code would be:
Unless your document’s been previously validated against a schema, you may want to make the last node test in the XPath
VIPair[Current and Voltage], so that the code doesn’t fail if there’s aVIPairelement that’s missing one of those child elements. (Alternatively, you might actually want the code to throw an exception if that happens; it really depends on the quality of the source data.)