任何人都可以向我解释为什么 xml1.Element(“title”)正确地等于“<title>Customers Main333</title>
”但 xml2.Element(“title”)令人惊讶等于 null ,即为什么我必须将XML文档作为元素而不是文档才能将元素拉出来?
var xml1 = XElement.Load(@"C:\\test\\smartForm-customersMain.xml");
var xml2 = XDocument.Load(@"C:\\test\\smartForm-customersMain.xml");
string title1 = xml1.Element("title").Value;
string title2 = xml2.Element("title").Value;
XML:
<?xml version="1.0" encoding="utf-8" ?>
<smartForm idCode="customersMain">
<title>Customers Main333</title>
<description>Generic customer form.</description>
<area idCode="generalData" title="General Data">
<column>
<group>
<field idCode="anrede">
<label>Anrede</label>
</field>
<field idCode="firstName">
<label>First Name</label>
</field>
<field idCode="lastName">
<label>Last Name</label>
</field>
</group>
</column>
</area>
<area idCode="address" title="Address">
<column>
<group>
<field idCode="street">
<label>Street</label>
</field>
<field idCode="location">
<label>Location</label>
</field>
<field idCode="zipCode">
<label>Zip Code</label>
</field>
</group>
</column>
</area>
</smartForm>