Просветите меня, как обрабатывать xml?
Есть у меня такой xml:
Код:
<?xml version="1.0" encoding="UTF-8"?>
<Model xmlns="http://www.esi-group.com/ns/VAOne" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.esi-group.com/ns/VAOne http://www.esi-us-rd.com/xml/schemas/VAOne/rev2/VAOne.xsd" name="Cube" note="">
<Version>1.1.0</Version>
<GlobalFrequencyDomain>
<FrequencyDomain start_freq="16" end_freq="8000" domain_type="2"/>
</GlobalFrequencyDomain>
<SolveOptions override_wavefields="false" beam_flexure_x="true" beam_flexure_y="true" beam_extension="true" beam_torsion="true" plate_extension="true" plate_flexure="true" plate_shear="true" average_radeff="false" symmetric_SEA_matrix="true" acoustic_pressure="true" compute_variance="false" solution_type="eHybrid" hybrid_quick="false" hybrid_quicknum="6" vsea_steps="20" override_eigen_frequencies="false" eigenlocallow="-5" eigenlocalhi="17826" eigengloballow="-5" eigenglobalhi="10695.6" local_mass="true" local_modes="false" modes="true" override_local_eigen_frequencies="false" override_global_eigen_frequencies="false" superelement_analysis="false" senqset="500" recover_fe_rad_eff="true" recover_nodal_eu="true" overrideGlobalAcousticEigenFreqs="false" getLocalAcousticModesInBand="true" minGlobalAcousticEigenValueFreq="-5" maxGlobalAcousticEigenValueFreq="10695.6" getAcousticModes="true" recoverBEM="true" overrideFEAcousticJunctionEps="false" feacousticJunctionEps="1e-006" recoverFEAcoustic="true">
<BulkDataCards/>
<ControlCards/>
</SolveOptions>
<Nodes>
<Node node_id="1" x="0" y="0" z="0"/>
<Node node_id="2" x="0" y="1" z="0"/>
<Node node_id="3" x="1" y="0" z="0"/>
<Node node_id="4" x="1" y="1" z="0"/>
<Node node_id="5" x="0" y="0" z="1"/>
<Node node_id="6" x="0" y="1" z="1"/>
<Node node_id="7" x="1" y="0" z="1"/>
<Node node_id="8" x="1" y="1" z="1"/>
<Node node_id="9" x="0.2" y="0.2" z="1"/>
<Node node_id="10" x="0.2" y="0.8" z="1"/>
<Node node_id="11" x="0.8" y="0.2" z="1"/>
...
...
Пытаюсь загрузить его в свою программу:
Код:
public class AutoSeaModel {
public XmlDocument xDoc = new XmlDocument();
public XmlElement xRoot;
String fileName;
public SortedDictionary<int, Node> nodes = new SortedDictionary<int, Node>();
public SortedDictionary<int, Face> faces = new SortedDictionary<int, Face>();
public SortedDictionary<String, Shell> shells = new SortedDictionary<String, Shell>();
public SortedDictionary<String, Cavity> cavities = new SortedDictionary<String, Cavity>();
public AutoSeaModel(String fileName)
{
this.fileName = fileName;
xDoc.Load(fileName);
xRoot = xDoc.DocumentElement;
XmlNodeList xNodes = xDoc.SelectNodes("/Model/Nodes/Node");
foreach(XmlElement xNode in xNodes) {
Node newNode = new Node(this, xNode);
nodes.Add(newNode.node_id, newNode);
}
XmlNodeList xFaces = xDoc.SelectNodes("/Model/Faces/FlatPlateFace");
foreach (XmlElement xFace in xFaces)
{
...
...
Вопрос мой в том, как использовать XPath?
По моим соображениям строка
XmlNodeList xNodes = xDoc.SelectNodes("/Model/Nodes/Node");
Должна вернуть набор XmlElement'ов, каждый из которых должен соответствовать строке типа
<Node node_id="1" x="0" y="0" z="0"/>
Но метод SelectNodes все время возвращает мне пустой список. Что я делаю не так?
Upd:
Все дело оказалось в пространстве имен XML. Помогла эта статья:
http://codehelper.ru/questions/102/n...ml-c-namespace