我必须分别获取列表中的所有实体源,实体目标,属性源和属性目标值。
<?xml version="1.0" encoding="utf-8" ?>
<Entities>
<Entity Source="E_cdclient" Target="cd_client">
<Property Source="KnowledgeItemId" Target="CLIENT_CONTACT_ID"/>
<Property Source="KnowledgeClientID" Target="CLIENT_CONTACT_ID"/>
</Entity>
<Entity Source="E_cdclientsystem" Target="cd_client_system">
<Property Source="PrimaryKnowledgeItemId" Target="0"/>
<Property Source="RelatedKnowledgeId" Target="0"/>
</Entity>
<Entity Source="E_cdclient_cdclientcontact" Target="cd_client_contact">
<Property Source="shortdescription" Target="analysis_short_description"/>
<Property Source="OWNERID" Target="REF_PROJECT_OWNER_ID"/>
</Entity>
</Entities>
我正在使用XDocument。
Public Function ReadXML() As List(Of String)
'Create the XML Document'
Dim m_xmld = New XmlDocument()
'Load the Xml file'
m_xmld.Load("C:\\MappingFile.xml")
'Get the list of name nodes'
Dim m_nodelist = m_xmld.SelectNodes("/Entities/Entity")
Return list
End Function
我该怎么做?
如何使用XDocument读取列表中XML的所有元素和子节点?
答案 0 :(得分:1)
Dim lElements = (From el In xml.Descendants("Entity")
Select Prop1 = el.Attribute("Prop1").Value, el.Value).ToList
此代码将为您提供具有2个属性的对象列表:
您可以使用所需的所有属性轻松扩展它。