0

Desired output something like:

<?xml version="1.0"?> <methodResponse> <params> <param> <value><string>South Dakota</string></value> </param> </params> </methodResponse> 

How do I use the xml-rpc powershell module to view the response?

Perhaps it's possible to "cat" or somehow pipe the result from baidu to something that will print it? Or, put it into an object?

PS /home/nicholas/powershell> PS /home/nicholas/powershell> Send-XmlRpcRequest -Url "http://ping.baidu.com/ping/RPC2" -MethodName "weblogUpdates.extendedPing" -Params @('jdon') xml methodResponse --- -------------- version="1.0" encoding="UTF-8" methodResponse PS /home/nicholas/powershell> 

or the more full request:

Send-XmlRpcRequest -Url "http://ping.baidu.com/ping/RPC2" -MethodName "weblogUpdates.extendedPing" -Params @('jdon','http://www.jdon.com/','http://www.jdon.com/47686','http://www.jdon.com/rss') 

generates a similar result. Something like:

$http = New-Object Chilkat.Http $xmlReq = "<?xml version=`"1.0`"?><methodCall><methodName>demo.sayHello</methodName><params /></methodCall>" $xmlResponse = $http.XmlRpc("http://www.cknotes.com/xmlrpc.php",$xmlReq) if ($http.LastMethodSuccess -ne $true) { $($http.LastErrorText) exit } $($xmlResponse) 

except, with this module, where is the response?

2 Answers 2

1

So your question is really "How do I convert an xml document to a string with nice and readable formatting" - the answer to which might look something like this:

function Convert-XmlToString { param( [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] [xml]$Xml ) begin { # Create formatting settings $writerSettings = [System.Xml.XmlWriterSettings]@{Indent = $true; OmitXmlDeclaration = $true} # Create StringBuilder $stringBuilder = [System.Text.StringBuilder]::new() } process { try { # Create XmlWriter $xmlWriter = [System.Xml.XmlTextWriter]::Create($stringBuilder, $writerSettings) # Write xml document to XmlWriter $xml.WriteContentTo($xmlWriter) # Flush XmlWriter to output target (ie. the stringbuilder) $xmlWriter.Flush() # Output resulting string $stringBuilder.ToString() } finally{ # Clean up $xmlWriter.Dispose() $stringBuilder = $stringBuilder.Clear() } } } 

With which you should be able to do something like:

PS C:\> $xmlRPCResponse = Send-XmlRpcRequest -Url "http://ping.baidu.com/ping/RPC2" -MethodName "weblogUpdates.extendedPing" -Params @('jdon','http://www.jdon.com/','http://www.jdon.com/47686','http://www.jdon.com/rss') PS C:\> $xmlRPCResponse |Convert-XmlToString <methodResponse> <params> <param> <value><string>South Dakota</string></value> </param> </params> </methodResponse> 
Sign up to request clarification or add additional context in comments.

3 Comments

Is there better URL and example parameter to test? Just to consume a response, or print it, really. as above.
@NicholasSaunders Sorry, I don't understand the question
it's okay, you answered the q, thank you. just looking for a more interesting example. no worries.
0

this is close:

PS /home/nicholas> PS /home/nicholas> $xmlRPCResponse = Send-XmlRpcRequest -Url "http://ping.baidu.com/ping/RPC2" -MethodName "weblogUpdates.extendedPing" -Params @('jdon','http://www.jdon.com/','http://www.jdon.com/47686','http://www.jdon.com/rss') PS /home/nicholas> PS /home/nicholas> $xmlRPCResponse | ConvertTo-Xml -As String <?xml version="1.0" encoding="utf-8"?> <Objects> <Object Type="System.Xml.XmlDocument">System.Xml.XmlDocument</Object> </Objects> PS /home/nicholas> 

although not quite the desired output.

thanks to Mathias, and see:

Powershell: Convert XML to String


better result:

PS /home/nicholas> PS /home/nicholas> $xmlRPCResponse.OuterXml <?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><int>0</int></value></param></params></methodResponse> PS /home/nicholas> 

although kind of a useless example. seems to work.

5 Comments

That's definitely not what you want - as you can see it has reduced the response object to the string System.Xml.XmlDocument, you've lost all the information you're trying to inspect :)
used the dot operator? seems okay.
No I'm talking about ConvertTo-Xml
right. doesn't $xmlRPCResponse.OuterXml visually "print" the xml to the console?
Yes, $OuterXml is indeed the string-representation of the xml document in question, so that'll work (although it won't format it nicely)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.