Get XML Value Issue - First Node has ':' Character


#1

I’m totally lost getting an XML element value from an XDocument. I’ve accessed and deserialized the xml string and needed to pull some values but am totally stuck. Here’s the beginning of the xml file:

<?xml version="1.0" encoding="UTF-8"?>
-<SearchResults:searchresults xmlns:SearchResults="http://www.zillow.com/static/xsd/SearchResults.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zillow.com/static/xsd/SearchResults.xsd http://www.zillowstatic.com/vstatic/64dd1c9/static/xsd/SearchResults.xsd">
<!-- H:002 T:89ms S:869 R:Thu Nov 02 16:12:27 PDT 2017 B:5.0.49502.34-hotfix_2017-11-02.95c71b6~hotfix-platform-for-2017-11-02.cccc807 -->
-<request>
<address>100 Main St</address>
<citystatezip>Gainesville FL 32607</citystatezip>
</request>
-<message>
<text>Request successfully processed</text>
<code>0</code>
</message>
-<response>
-<results>
-<result>
<zpid>4658112</zpid>

I was following the UiPath ‘How to…’ and tried to use

xmlDoc.Element(“SearchResults:searchresults”).Element(“response”).Element(“results”).Element(“result”).Element(“zpid”).value

and ran into The ‘:’ character, hexadecimal value 0x3A, cannot be included in a name error. Tried following the ‘Get XML element value (with namespaces)’ article and created

XNamespace SearchResults = "http://www.zillow.com/static/xsd/SearchResults.xsd"
XElement tempElement = xmlDoc.Descendants(SearchResults + “searchresults”).FirstOrDefault();

but not sure how to proceed and now I’m totally lost. Would someone please point me in the right direction on how can I get to the next step and find the value of the “zpid”? I can write out the entire first node but stuck there. Thanks.


#2

Hi ,

Please find below tutorials on XML type handling

Thanks,
Karthik.