Get XML element value (with namespaces)

studio

#1

I’m trying to get element value using namespaces but i get this error: Message box : The ‘:’ character, hexadecimal value 0x3A, cannot be included in a name


#2

Hello, try to use “{ }” or if it’s dynamic which is like, “is dynamic :astonished:

<ab:xlvalue>Str</ab:xlvalue>
XNamespace ab = "http://your-url";
XElement tempElement = doc.Descendants(ab + "xlvalue").FirstOrDefault();

this way it will look for an xmlns:ab=… section in your document to find out which namespace URI “ab” refers to.

You can get it by finding the attribute value for XNamespace.Xmlns + “ab”

let us knwo if this is the answer you are looking for :slight_smile:


Read XML files and get data - Namespaces
#3

Yes, thank you, I created variables Xnamespace and it worked!


#5

@Timber I have the same issue. How did you solve it?


#7

Hello @Timber and @andnesper,

any suggestions how to fix it? Here’s my Code that does not work for the same reason: Botadministration.zip (43.7 KB)

Thanks
Kind regards
Gennaro


#8

You have to create XNamespace variables, I edited you xaml.

Main.xaml (6.1 KB)


#9

Hi @Timber,

thanks for your reply. Actually it just Returns “System.activities” which means Nothing. I wanted to get the value of “x:class” which is “Main”.

So in this instance I was hoping to get “main”. Any help?

Thanks a lot
Gennaro


#10

Hey @Gennaro_Bozza,

It was just an example to get something from XML using namespaces, it returns this:

In order to get “Main” you have to access ‘Activity’ element’s x:Class attribute:

Main.xaml (6.0 KB)


#11

hi @Timber

thanks a lot for your really helpful reply! I am starting to understand well the mechanism. Yet, the following line does not work:
xmlDoc.Element(activities+“Activity”).Element(activities+“Sequence”).Element(ui+“ExcelApplicationScope”).Attribute(“DisplayName”).Value

that I would like to use to obtain the DisplayName.

I have initialised “ui” with “clr-namespace:System.Collections.ObjectModel;assembly=mscorlib”. Maybe I should have initialised it with something else?

Furthermore, I would like to extract all of the workflow comprised within, for example, xmlDoc.Element(activities+“Activity”).Element(activities+“Sequence”). How can this be done?

Please let me know, your help is very appreciated.
Kind regards,
Gennaro


#12

create XNamespace variables with these values:

So in this case ui = “http://schemas.uipath.com/workflow/activities


#13

I didn’t understand the second part, what exactly do you want to extract from this xml?


#14

hi @Timber,

thanks! now it works well! As far as the workflow to extract is concerned, let’s assume the following:

<Element 1>
<Element 2>
<Element 3>
</Element 3>
</Element 2>
</Element 1>

Well, I would like to extract for example everything within Element 2, or Element 3 etc.

Any clues?
Many thanks
Gennaro


#15

Adding .ToString will give you all element as string: xmlDoc.Element(activities+“Activity”).Element(activities+“Sequence”).ToString =


#16

Hi Timber,

I am trying to get element value .
But I am getting error as,
“Deserialize xml : ‘\’ is an unexpected token. The expected token is '”’ or ‘’’. Line 1, position 15.",

My XML is,

<?xml version=\"1.0\" encoding=\"utf-8\"?>
<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">
	<soap:Body>
		<SearchSecretsByFolderResponse xmlns=\"urn:thesecretserver.com\">
			<SearchSecretsByFolderResult>
				<Errors />
				<SecretSummaries>
							
				<SecretSummary>
					<SecretId>63</SecretId>
					<SecretName>s7982</SecretName>
					<SecretTypeName>Active Directory Account - Robotics</SecretTypeName>
					<SecretTypeId>638</SecretTypeId>
					<FolderId>66</FolderId>
					<IsRestricted>false</IsRestricted>
				</SecretSummary>
				
				<SecretSummary>
					<SecretId>64</SecretId>
					<SecretName>s7983</SecretName>
					<SecretTypeName>Active Directory Account - Robotics</SecretTypeName>
					<SecretTypeId>68</SecretTypeId>
					<FolderId>66</FolderId>
					<IsRestricted>false</IsRestricted>
				</SecretSummary>
			</SecretSummaries>
		</SearchSecretsByFolderResult>
	</SearchSecretsByFolderResponse>
</soap:Body>

</soap:Envelope>


#17