Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7445443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:49:26+00:00 2026-05-29T11:49:26+00:00

Basically I have an XML file that looks like this: <?xml version=1.0 encoding=UTF-8?> <data>

  • 0

Basically I have an XML file that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<data>
<sender sndid="FT">
    <val n="name">Oy Finntack Ltd</val>
    <val n="address1">Keskikankaantie 29-31</val>
    <val n="zipcode">15860</val>
    <val n="city">Hollola</val>
    <val n="country">FI</val>
    <partner parid="POSTI">
        <val n="iban">FI2515193000110201</val>
        <val n="bic">NDEAFIHH</val>
        <val n="postgiro">15193000110201</val>
        <val n="custno">632368</val>
    </partner>
</sender>
<receiver rcvid="109480">
    <val n="name">Petra Kern</val>
    <val n="address1">Ziegelgasse 14</val>
    <val n="zipcode">73525</val>
    <val n="city">Schwabisch Gmund</val>
    <val n="country">DE</val>
</receiver>
<shipment orderno="635023">
    <val n="reference"/>
    <val n="from">FT</val>
    <val n="to">109480</val>
    <service srvid="IT14">
        <addon adnid="mprc"/>
        <val n="returnlabel">no</val>
    </service>
    <container measure="parcel" type="parcel">
        <val n="reference">PCK00000160</val>
        <val n="copies">1</val>
        <val n="weight">0.3</val>
        <val n="contents"/>
        <val n="packagecode">pc</val>
        <val n="marking">horze-finntack</val>
    </container>
</shipment>

I am writing a Windows service that checks a folder for XML files at a given interval, parses them one at a time for some specific information (to address, from address, and shipment contents) this data is then send via a proprietary method to be rated, shipped, and tracked. All this code works fine, my problem is accessing XML in VB .Net (I am a PHP programmer, and could have this done in 10 minutes if this was a web app). Anyways, here is some code. This Sub searches Path for all files that end in Ext, then for each file found will grab certain information from the XML file and send it in for processing.

    Sub GetXMLFiles()
    //declare some variables
    Dim fName As String
    Dim Files = New ArrayList
    Dim I As Integer = 1
    Dim dirInfo As New DirectoryInfo(Path)
    Dim fileInfos() As FileInfo = dirInfo.GetFiles(Ext)
    For Each file_info As FileInfo In fileInfos
        fName = file_info.FullName
        Try
            Dim xDoc As XPathDocument = New XPathDocument(fName)
            Dim xNav As XPathNavigator = xDoc.CreateNavigator()

            //from here until the end of this Try statement is just a test.
            Dim sender As XPathNodeIterator
            sender = xNav.Select("/data/sender")
            While (sender.MoveNext())
                Console.WriteLine(sender.Current.Value)
            End While
            //end test

        Catch ex As Exception

        End Try
        Files.Add(Path & fName)
    Next file_info

End Sub

In the end this will be threaded, as the XML results will be transmitted via REST and the time it takes to process each request is indeterminable.

So here is my question/problem. After I create the Navigator, I could use XPath expressions like in the test to select a certain node. But after I select that node, I am unable to access its children by name. If you notice the XML the attributes for the <sender> element are not named properly they are <val n="name"> What I need returned is each <val> that is a direct child of <sender> (the <partner> section is omitted for my purposes). This same thing applies to the <receiver> element. The <shipment> element will possibly contain multiple <container> elements, but I can deal with that once I can figure out how to return everything correctly. What I need for each <val> in <sender> is the n="[NAME]" and the actual value of <val>.

If you look at first <val> in the <sender> block of the provided XML I would want a to have two variables Name and Value that for the first example would be name,Oy FinnTack Ltd.

I know I am close! Sorry for the long post but I attempt to answer too many questions on stackoverflow where the person is very vague on what they are trying to do.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:49:27+00:00Added an answer on May 29, 2026 at 11:49 am

    You’re pretty much on the right track. You want to use XPathNavigator.SelectChildren to accomplish this:

    public virtual XPathNodeIterator SelectChildren(
        string name,
        string namespaceURI
    )
    

    I loaded up your sample XML file and processed it using the following code:

    Option Infer On
    Option Explicit On
    Option Strict On
    
    Imports System.Xml
    Imports System.Xml.XPath
    
    Module Module1
    
        Sub Main()
            ParseXml("Test.xml")
            Console.ReadLine()
        End Sub
    
        Public Sub ParseXml(ByVal fn As String)
            Dim xd = New XPathDocument(fn)
            Dim xn = xd.CreateNavigator()
    
            Dim sender = xn.SelectSingleNode("/data/sender").SelectChildren("val", String.Empty)
            While (sender.MoveNext())
                Console.WriteLine("Name: {0}, Value: {1}", sender.Current.GetAttribute("n", String.Empty), sender.Current.Value)
            End While
        End Sub
    
    End Module
    

    The output is as follows:

    Name: name, Value: Oy Finntack Ltd
    Name: address1, Value: Keskikankaantie 29-31
    Name: zipcode, Value: 15860
    Name: city, Value: Hollola
    Name: country, Value: FI
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ok, so, i have an xml file that looks like this: <?xml version=1.0?> <Users>
I know that if I have an XML file like this: <persons> <class name=English>
I have the following mapping file: <?xml version=1.0 encoding=utf-8 ?> <hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 assembly=Project1.Accounts namespace=Project1.Core.Domain>
I have an xml file that I need to load. This xml file holds
I have an xml sitemap structured like a document tree, such that it looks
i have the following XSL that will transform an XML file and basically flatten
I have a bit of code that basically reads an XML document using the
I have an html-like xml, basically it is html. I need to get the
I basically have something like this: void Foo(Type ty) { var result = serializer.Deserialize<ty>(inputContent);
I have a template function in C++ that basically writes values to an XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.