Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to get all the Entity Source,Entity Target,Property Source and Property Target values in list respectively.

XML
<?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>



I am using Xdocument.

VB
Public Function ReadXML() As List(Of String)

        Dim list As New List(Of String)
        Dim m_xmld As XmlDocument
        Dim m_nodelist As XmlNodeList
        Dim m_node As XmlNode

        Dim SourceAttribute As String = ""
        Dim TargetAttribute As String = ""
        Dim PropertySource As String = ""
        Dim PropertyTarget As String = ""
        'Create the XML Document
        m_xmld = New XmlDocument()

        'Load the Xml file
        m_xmld.Load("C:\\MappingFile.xml")

        'Get the list of name nodes
        m_nodelist = m_xmld.SelectNodes("/Entities/Entity")
    .
    .
    .
    .

  Return list
    End Function



How can I do this?
Posted
Updated 6-Jul-11 2:29am
v2

1 solution

Do this after you get the node list:

VB
Dim entSource As String
Dim propSource As String 
Dim propTarget As String 
For Each node As XmlNode In m_nodelist
    'Get the entity source value
     entSource = node.Attributes("Source").Value
    'list.Add(entSource);
    For Each childNode As XmlNode In node.ChildNodes
        'Get the property source value
        propSource  = childNode.Attributes("Source").Value
        'list.Add(propSource)
        'Get the property source value
        propTarget = childNode.Attributes("Target").Value
        'list.Add(propTarget)
    Next
Next


If you want to add it in some list, write list.Add(..) after each string declaration.
Hope this helps.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900