Hab jetzt mal die 2 Varianten ausprobiert:
where xEle.Element("Property").Attribute("name").Value == "Left"
where xEle..Attribute("name").Value == "Left"
Leider steht in der Variable x weiterhin NULL.
Was wäre euer Vorschlag?
Hi Leute,
ich bin noch relativ neu in dem Forum und auch in der C# Programmierung und bräuchte mal eure Hilfe.
Ich versuche aus einer XML 2 bestimme Werte auszulesen. Und zwar die Werte aus dem Element "Geometrie" -> "Left" & "Top" .
Hier die XML dazu.
<Objekt name="Rechteck1">
<Gruppe name="Blinken">
<Property name="FlashBorderColor">0</Property>
<Property name="BorderFlashColorOff">16776960</Property>
<Property name="BorderFlashColorOn">255</Property>
<Property name="FlashRateBorderColor">1</Property>
<Property name="FlashBackColor">0</Property>
<Property name="BackFlashColorOff">65280</Property>
<Property name="BackFlashColorOn">16776960</Property>
<Property name="FlashRateBackColor">1</Property>
</Gruppe>
<Gruppe name="Darstellung">
<Property name="GlobalShadow">1</Property>
<Property name="GlobalColorScheme">1</Property>
<Property name="Transparency">0</Property>
</Gruppe>
<Gruppe name="Farben">
<Property name="BorderColor">0</Property>
<Property name="BorderBackColor">16777215</Property>
<Property name="BackColor">8421504</Property>
<Property name="FillColor">65280</Property>
</Gruppe>
<Gruppe name="Fuellen">
<Property name="Filling">0</Property>
<Property name="FillingIndex">0</Property>
<Property name="FillingDirection">0</Property>
</Gruppe>
<Gruppe name="Geometrie">
<Property name="Left">40</Property>
<Property name="Top">110</Property>
<Property name="Width">450</Property>
<Property name="Height">90</Property>
</Gruppe>
<Gruppe name="Objekt">
<Property name="ObjectName">Rechteck1</Property>
<Property name="Layer">0</Property>
</Gruppe>
<Gruppe name="Sonstiges">
<Property name="Operation">1</Property>
<Property name="PasswordLevel">0</Property>
<Property name="Visible">1</Property>
<Property name="ToolTipText" />
</Gruppe>
<Gruppe name="Stile">
<Property name="BorderWidth">1</Property>
<Property name="BorderStyle">0</Property>
<Property name="FillStyle">0</Property>
<Property name="DrawInsideFrame">1</Property>
</Gruppe>
</Objekt>
Hier mein Quellcode dazu:
//XML einlesen
element = XElement.Load(file);
var x = from xEle in element.Descendants("Geometrie")
where xEle.Attribute("Property name").Value == "Left"
select xEle;
var x2 = from xEle in x.Elements("Left") select xEle;
Wobei ich hier nur einen der beiden Werte versuche auszulesen. Allerdings funktioniert es nicht, in der Variable x und x2 steht jeweils NULL.
Hat jemand eine Idee wie ich anders an die Werte rankomme und diese in einer Variable speicher kann? Die XML darf allerdings nicht verändert werden.
Vielen Dank vorab und beste Grüße.