Reading xml - xmlDocument

I am having a problem when trying to read an xml through invoke code, I have the following script

DocumentXML = New System.Xml.XmlDocument()
DocumentXML.Load(Path)

But it generates the following error
Invoke Code: No compiled code to run
error BC31051: Namespace or type ‘System.Xml.XPath’ has already been imported. At line -2

I don’t quite understand what I should do

Hi @Juan_Esteban_Valencia

Remove the import statement for ‘System.Xml.XPath’:

  • Open the Invoke Code activity.
  • Check if there is an import statement for ‘System.Xml.XPath’ at the beginning of the code.
  • If present, remove the import statement for ‘System.Xml.XPath’.

Hello, thanks for the answer, but reviewing the invoke code, there are only these two lines
DocumentXML = New System.Xml.XmlDocument()
DocumentXML.Load(Path)
image

@Juan_Esteban_Valencia Can you show me your variables type

@Juan_Esteban_Valencia
Use a different script activity: Instead of using the Invoke Code activity, you can try using other activities specifically designed for XML processing, such as the Read Text File and Deserialize XML activities. These activities provide a more straightforward way to read XML files in UiPath.

Of course, look at them

what happens is that the output variable should be XmlDocument, and the UiPath activities give me an output variable XDocument

Hi guys, I already managed to detect the problem, in the sequence where the invoke code was hosted, for a strange reason when opening it with notepad++ I detected that the line <x:String>System.Xml.XPath</x:String> was repeated , what I did was delete one, save the file and run the project again
It worked!

Thank you very much for everyone’s collaboration
image

3 Likes

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