Value returned from blank Xpath

Hi,

I am learning how to handle XML and I believe xpath will be the way to get the information you need. I can understand the syntax, but the value returned from xpath is always blank. can someone help me and check if there are any errors.

I searched other topics and learned how to deal with xpath, but I can’t understand why it doesn’t return me nNF that should be “10410”

teste.zip (16.9 KB)

I am unable to open your .XAML - it says “error detecting project version” when trying to open it.

I can see the XML though, what node are you trying to reach? Also, make sure you are dealing with the namespace properly, as that has caused me a lot of problems in the past (i still don’t really understand the point of namespaces, just seems to complicate everything)

Hi Dave,

When this error happens I delete the project.json file and open xaml

It works again. xml is inside the zip

I don’t know much about XML (nothing to be honest) so I don’t know what namespaces mean

thanks,

I got it with this command

xml_Doc.descendants().Where(function(n)n.Name.LocalName = “nNF”).value
:grinning:

4 Likes

Just an FYI that this is just normal xml navigation not xpath. It’s the way I always navigate XMLs as well

1 Like

@KMota
While I was working on your issue, you solved by yourself. Great :+1:

xpath: “string(//*[local-name()=‘nNF’]/text()[1])” would return the value.

Go on with the API that you currently used in your solution. I feel its easier to use on the start. And you are doing similiar, working with the local name.

And it was the issue with the namespaces.

A namespace let you allow to group elements in so called namespaces. In case you have more namespaces in use and e.g. some elements have the same name e.g. , you can identify those elements by using the namspace into account:
e.g. namspace1 has x: as an alias so element person is identified by x:person

Just in brief: <NFe xmlns="http://www.portalfiscal.inf.br/nfe"> Bold formatted part is defining the namespace, unfortenately with an alias. So option to direct adress nNF were gone.

About namespaces more in detail, come back on a seperate post and we help you.

1 Like

Hi ppr,

thank you for your attention, your explanation was very clear. I’m walking, now I need to read a folder with multiple xml and extract the information, one by one and insert into another app. I’m trying if I can’t open another topic. thank you very much :slight_smile:

I tested your xpath solution and it worked perfectly too :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.