Important Update: Some Community URL Redirects are Under Maintenance. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Webservice SearchRecordsByReport emits invalid xml that has <br> without closing </br>

MarkKnutson
Contributor

$api_url = $base_url + "/ws/search.asmx"
$ws = New-WebServiceProxy -Uri $api_url -Class Search -Namespace webservice
$report_id = "15123436-A0A6-44DF-93D7-FF3C5DD18BBB"
$xml_file = New-Object System.Xml.XmlDocument
$page = 1

Do {
[xml] $xdoc = $ws.SearchRecordsByReport($session_token, $report_id, $page)
if ($page -eq 1) {
$xml_file = $xdoc
}
else {
ForEach ($record in $xdoc.SelectNodes("/Records/Record")) {
$records = $xml_file.SelectSingleNode("/Records")
$records.AppendChild($xml_file.ImportNode($record, $true)) | Out-Null
}
}
Write-Output "$("page: ",$page)"
$page++
} While ($xdoc.Records.Record.Count -gt 0)

 

[System.Web.HttpUtility]::HtmlDecode($xml_file.InnerXml) | Out-File "c:\temp\outfile.xml"

 

Any help much appreciated. I added the htmldecode because I was getting xml with '&lt' instead of '<' and so forth.

 

One thing I can do is simply delete all the <br> tags. The purpose of getting the xml is to get it into a format readable by excel or power bi such as a csv file. Any guidance on this is also very much appreciated.

 

Also, if there is any documentation on the structure of the xml coming out of this, I would love to look at it. The webservice manual only states that xml is emitted. thanks

3 REPLIES 3

DavidFreeman
Archer Employee
Archer Employee

Hi Mark,

 

This is from one of the examples on LINK and it returns the XML as you'd expect.

 

000032488 - How to use the RSA Archer Web Services API with Windows PowerShell 

 

You should use the report ID instead of the GUID, as well.  You can get the report ID in the master reports listing.  Hover over the report and the ID is displayed in the lower right.

 

###########################################################################################################################################
# LOGIN to get the session token using Web Services API. Display the session token or exit.
###########################################################################################################################################
try
{
$api_url = $base_url + "/ws/general.asmx"
if ($user_domain -eq "") {
$ws = New-WebServiceProxy -Uri $api_url -Class General -Namespace webservice -ErrorAction Stop
$session_token = $ws.CreateUserSessionFromInstance($username, $instance, $password)
}
else {
$ws = New-WebServiceProxy -Uri $api_url -Class General -Namespace webservice -ErrorAction Stop
$session_token = $ws.CreateDomainUserSessionFromInstance($username, $instance, $password, $user_domain)
}
$session_token
}
catch {
$session_token = $null
$_.Exception|Format-List -Force
exit
}


###########################################################################################################################################
# Get the All Facilities report (ID: 159) and loop thru the results.
###########################################################################################################################################
$api_url = $base_url + "/ws/search.asmx"
$ws = New-WebServiceProxy -Uri $api_url -Class Search -Namespace webservice
$report_id = 9895
$page = 1

Do {
"Page " + $page
[xml] $xdoc = $ws.SearchRecordsByReport($session_token, $report_id, $page)
$xdoc.InnerXml
$page++
} While ($xdoc.Records.Record.Count -gt 0)

MarkKnutson
Contributor

Thanks for responding. I just ran it with a single page and had it save the innerxml to a file. Visual studio won't open the file because it is reporting a missing root document error. Same with xml notepad. When I view the text, I note a lot of '&lt;li&gt;Program personnel' where the greater and less than are escaped in html format. Also, we would like to get all the pages of the report. If we simply concatenate them, I think it will not be a well formed xml document due to duplication of header elements as each page will be a complete document. The goal we have here is to take this report and load it into power bi or excel. My intermediate goal here is to get a well formed xml document with  all the pages of a report. I also have questions about the structure of the xml that is emitted here when the time comes to extract the data. I have gotten past some of these issues using code samples from others here, but there is at the very least the unmatched <br> tag problem. I want to do this the right way, so whatever the process is, I can follow it. Also, in the referenced article there is a hyperlink to a KB article, but the link is no longer valid. Just FYI on that one.

 

Is there an xml stylesheet that can be used with this report output?

 

I know its a lot of questions, but they are questions I  have been struggling with. I have spent all of this week working on this, and am a bit stuck, so any help is appreciated.

DavidFreeman
Archer Employee
Archer Employee

Hi Mark,

 

Sorry for the delay.  You'll need all the XML because it will not be well-formed if you just take a sub-component.  If that's the way you want to do it, you'll need to wrap your XML output accordingly.

 

If you create a transport data feed with a simple report, the resulting XML will give you an idea of how the reports are formatted.  The first thing is understand is the Field Definitions section.  From there, it a matter of learning the hierarchy of the Record node.  It can be a challenge to understand.  But if you have a tool which can show you the leveled nodes, that will help you get a grip on it.

 

After that, you can then create some XSLT which will allow you to form the import to your analysis tool, if you're pursuing XML.  Otherwise, you could use the APIs for the applications to chat back and forth.  You can take the output as an XML or JSON object for the target system to manipulate.

 

I believe that the escape codes are coming back from text fields.  In order to pass those through you'll need to wrap the responses in CDATA.  That should get you where it needs to be on the other side.  

 

I'll tag David Petty‌ as he likely has some additional input.

 

David