Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts
Windows Powershell: Invoking a Web Service
Ozzie
About a year ago I posted about invoking a Web Service using Windows Powershell v3 CTP 1. Powershell v3 is the standard on Windows 8 and Windows 2012 Server. However, I learned that you don’t need to use v3, because there is a very nice cmdlet one can use to invoke Web services through a proxy object. It’s called New-WebServiceProxy.
So here is the example of invoking a stock quote Web service using powershell with the proxy cmdlet:
The outcome should be something like this:
On the above example I invoked the “getQuote” method. After instantiating the proxy on the $stock variable, if you’d like to learn what methods are available, as well as the parameters and return types, you can type at the prompt:
Overall, it’s a more powerful solution than the previous one I presented because you get to instantiate a proxy object with all the methods and properties of the Web service and it’s more compatible since you don’t need to upgrade.
Happy coding!
So here is the example of invoking a stock quote Web service using powershell with the proxy cmdlet:
- $URI = "http://www.webservicex.net/stockquote.asmx?WSDL"
- $stock = New-WebServiceProxy -uri $URI
- $xml = [xml]$stock.getQuote("MSFT")
- $xml.StockQuotes.Stock
On the above example I invoked the “getQuote” method. After instantiating the proxy on the $stock variable, if you’d like to learn what methods are available, as well as the parameters and return types, you can type at the prompt:
- $stock | get-member -type method
Happy coding!
4:13 PM
Powershell
,
Programming
,
XML
Python, Oracle and LOB objects
Ozzie
The Python programming language is my preferred tool to develop quick and (sometimes) dirty scripts to perform single shot data processing tasks.
Recently, one of these tasks involved querying a table with a LOB column that stores XML strings. So the challenge was to read the LOB column and parse as string to dump the records to file.
My setup is Python 2.7 with the CxOracle 5.0.4 library. The first try I ran into the “LOB variable no longer valid after subsequent fetch” exception. According to the documentation this is because internally, Oracle uses LOB locators which are allocated based on the cursor array size. Thus, it is important that the data in the LOB object be manipulated before another internal fetch takes place. It also states that the safest way to do this is to use the cursor as an iterator.
Well, that’s all very nice, but I wouldn’t hang a cursor on a whole table, fetching the records one-by-one and processing the whole XML before going for another fetch. That’s not advisable on an OLTP database.
My solution and suggestion to other python users is to perform a two step fetch process:
Recently, one of these tasks involved querying a table with a LOB column that stores XML strings. So the challenge was to read the LOB column and parse as string to dump the records to file.
My setup is Python 2.7 with the CxOracle 5.0.4 library. The first try I ran into the “LOB variable no longer valid after subsequent fetch” exception. According to the documentation this is because internally, Oracle uses LOB locators which are allocated based on the cursor array size. Thus, it is important that the data in the LOB object be manipulated before another internal fetch takes place. It also states that the safest way to do this is to use the cursor as an iterator.
Well, that’s all very nice, but I wouldn’t hang a cursor on a whole table, fetching the records one-by-one and processing the whole XML before going for another fetch. That’s not advisable on an OLTP database.
My solution and suggestion to other python users is to perform a two step fetch process:
- Fetch all relevant primary keys from the table;
- Fetch the LOB column one-by-one using the PK list from the previous step.
def executaQueryLOB(txtQuery):
import cx_Oracle
orcl = cx_Oracle.connect('yourConnectioString')
curs = orcl.cursor()
curs.execute(txtQuery)
result=curs.fetchall()
strLOB=result[0][0].read()
orcl.close()
return strLOB
HTH.
4:04 PM
LOB
,
Programming
,
python
,
XML
Free alternative to XML Spy
Ozzie
Professionally I'm sometimes faced with the challenge of being assigned a task, without having the adequate tools to perform it. An example of that is working with XML files.
Not having acquired a commercial software like XML Spy, I had to find a free alternative. To open XML files, pretty-print them and check for issues, I adopted XML Copy Editor:

XML Copy Editor is a free editor that enables you to:
Not having acquired a commercial software like XML Spy, I had to find a free alternative. To open XML files, pretty-print them and check for issues, I adopted XML Copy Editor:
XML Copy Editor is a free editor that enables you to:
- open XML files
- edit your own XML
- check if the XML is well formed
- check the XML for compliance with a given schema
Additionally it also performs advanced user operations like syntax highlighting and XPath evaluations. Overall, XML Copy Editor performs all the tasks necessary for XML analysis.
Subscribe to:
Posts
(
Atom
)