Working with XML

HI team,

I know there are other topics regarding this subject, but I have never worked with XML and I can’t understand about elements, attributes …
I tried to risk with the content I saw, but nothing. I need to extract from the XML the

nNF, dhEmi, emit><CNPJ, vICMS

I need to extract this information from various XML
within a directory and then fill it in another application and I don’t even know how to get started. Can someone give me a push rs a north to start.
remembering that I’ve read tutorials like this

samplexaml.zip (16.8 KB)

thanks

This may help get to grips with it using a simple example

Hi ronanpeter,

Thank you, I will check the example you sent me and try something. I tell you if something will come out lol

Ronanpeter,

xmlDoc.Element(activities+“Activity”).Attribute(x + “Class”).Value

xmlDoc.Element(activities+“Activity”) is the anchor, right?

I can’t identify why it changes in the case of “x”

I understand your code, but I have difficulty locating the anchor and attributes by myself, I’m looking for the XML structure the electronic invoices of the Brazil to try to understand, but it’s hard lol

the x references a variable which points to a namespace (xlmns detailed at the top of xml files). So for certain nodes in the XML they will be prefixed with these to avoid conflicts in the naming of resources in the file, and are created by the author. They can be named anything really but on occasion you’ll see the use of URLs, used simply because they are unlikely to be conflicts, they perform no technical functionality.

You can simplify their use in UiPath by creating a variable, in this case ‘x’, which has a value of the corresponding Url (“http://schemas.microsoft.com/winfx/2006/xaml”)

I hope that makes sense.

Got it, a little
could you give me a tip bring the NNF to try to continue

teste.zip (16.8 KB)

Analysing your xml shows that {http://www.portalfiscal.inf.br/nfe} is the namespace.

There is certainly a more direct way of doing this but this basically allows you just to give the Xelement name that you wish to see the value of. You should just be able to directly act on the XML object through the element names, but it is possibly due to the value types I have been passing. However this is a workaround for now.

In your case, you simply provide the bot with the name of the element, “nNF” and it will return the value, “10410”. It will work for all others as well.

IterateXML_Example1.zip (5.8 KB)

1 Like

thanks, I think I’ll have to use xpath. I will test your example. Thanks ronanpeter

thanks,

I got it with this command

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

1 Like

Nice work. Basically the same function as I had worked through, but much more elegant.

1 Like

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