Results 1 to 2 of 2

Thread: Get data from "xml" file

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    6

    Get data from "xml" file

    Hello,

    I have some *.sym file, what is in xml format.
    Next to end of the file there is QuotationInfo block, I need to get all symbol name value from the <Info num="4" name="Contained Symbols"

    <QuotationInfo>
    <Info num="0" name="Number of Loops" value="2"/>
    <Info num="3" name="Number of Contained Symbols" value="2"/>
    <Info num="4" name="Contained Symbols">
    <Symbol name="U-6088-DF-20-3-POS40-D" count="1"/>
    <Symbol name="U-6088-DF-20-3-POS70-D" count="1"/>
    </Info>
    <Info num="5" name="Number of Tools">

    Anybody can show how can I get these values?
    I attached an exaple symbol file the this post.


    Best Reagrds,

    Tibi
    Attached Files Attached Files

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: Get data from "xml" file

    Assuming that the file is an XML file, this should help.

    Code:
            Dim xe As XElement
    
            'to load from file
            '  xe=XElement.Load("your path here")
    
            'to test
            xe = <root>
                     <QuotationInfo>
                         <Info num="0" name="Number of Loops" value="2"/>
                         <Info num="3" name="Number of Contained Symbols" value="2"/>
                         <Info num="4" name="Contained Symbols">
                             <Symbol name="U-6088-DF-20-3-POS40-D" count="1"/>
                             <Symbol name="U-6088-DF-20-3-POS70-D" count="1"/>
                         </Info>
                         <Info num="5" name="Number of Tools"/>
                     </QuotationInfo>
                 </root>
    
            Dim ie As IEnumerable(Of XElement)
    
            ie = From el In xe...<QuotationInfo>.Elements
                 Where el.Name.LocalName = "Info" AndAlso el.@num = "4" AndAlso el.@name = "Contained Symbols"
                 From sel In el.Elements Select sel
    
            For Each el As XElement In ie
                Debug.WriteLine("{0}  {1}", el.Name.LocalName, el.@name)
            Next
    How well it works depends on the actual file format. Attaching a sample file would help.
    Last edited by dbasnett; Jul 27th, 2016 at 06:25 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Tags for this Thread

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