Get XML element value (with namespaces)

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

1 Like

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:

3 Likes

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

1 Like

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

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

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

Main.xaml (6.1 KB)

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

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:

cap2

Main.xaml (6.0 KB)

3 Likes

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

create XNamespace variables with these values:

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

1 Like

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

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

1 Like

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

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>