Results 1 to 2 of 2

Thread: How to read XML files?

  1. #1

    Thread Starter
    Lively Member neodatatype's Avatar
    Join Date
    Aug 2002
    Location
    Italy
    Posts
    103

    How to read XML files?

    Hi all,

    Can someone tell me how can I have direct access to XML element/attribute?

    sample:


    <project name="myproject" attribute "myattribute">
    <myelement name="elementname" />
    <nestedelement x="1" y="2">
    <row>first row</row>
    </nestedelement >
    </project>



    Task 1: I want to know the attribute "name" of element "project"

    Task 2: I want to know the attribute "name" of element "myelement"

    Task 3: I want to know the element string of element "row"

    All I got from sites and tutorials is how to parse the XML file and list alla elements/attributes, but I don't need a parsing, I need to go directly to an element and get its attributes.

    How?

    Thank you!
    > NeoDataType.net <

    Try my Free .Net Reporting Tool!

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You can load it into a DataSet with the DataSet's ReadXML method or Load it into an XMLDocument and use the SelectSingleNode method to get what you need.

    VB Code:
    1. 'load into a DataSet
    2. Dim ds As New DataSet()
    3. ds.ReadXml("..\xmlfile1.xml")
    4. MsgBox(ds.Tables(0).Rows(0)("name"))
    5.  
    6. 'load it into a XMLDocument
    7. Dim xdoc As New Xml.XmlDocument()
    8. xdoc.Load("..\xmlfile1.xml")
    9. Dim xNode As Xml.XmlNode = xdoc.DocumentElement.SelectSingleNode("/project")
    10. MsgBox(xNode.Attributes("name").Value)

    *Also you need an = sign in here [attribute "myattribute"]
    Last edited by Edneeis; Feb 23rd, 2003 at 03:15 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width