Parsing Typed XML with a default namespace and inconsistent root node I have a structured, typed xml file.

&lt;WebService xmlns="http://www.orbis-software.com/WebSvcCon"&gt;
 &lt;NewLeads&gt;
  &lt;OutputSchema&gt;
  &lt;root xmlns="" type="array"&gt;
   &lt;item type="object"&gt;
   &lt;SaleProperty type="object"&gt;
    &lt;Type type="string"&gt;Freehold&lt;/Type&gt;
    &lt;PostDistrict type="string"&gt;xxx&lt;/PostDistrict&gt;
    &lt;Address type="string"&gt;address&lt;/Address&gt;
     &lt;Value type="number"&gt;17.0&lt;/Value&gt;
   &lt;/SaleProperty&gt;
   &lt;Transaction type="string"&gt;SaleOnly&lt;/Transaction&gt;
   &lt;Quote type="object"&gt;
    &lt;Sale type="object"&gt;
     &lt;Fees type="number"&gt;450.0&lt;/Fees&gt;
     &lt;Disbursements type="number"&gt;0.0&lt;/Disbursements&gt;
     &lt;StampDuty type="number"&gt;0.0&lt;/StampDuty&gt;
     &lt;Total type="number"&gt;450.0&lt;/Total&gt;
    &lt;/Sale&gt;
   &lt;Discount type="number"&gt;0.0&lt;/Discount&gt;
   &lt;VAT type="number"&gt;90.0&lt;/VAT&gt;
   &lt;Total type="number"&gt;540.0&lt;/Total&gt;
  &lt;/Quote&gt;
  &lt;MoverId type="number"&gt;12345678&lt;/MoverId&gt;
  &lt;Name type="string"&gt;Mr AS&lt;/Name&gt;
  &lt;Email type="string"&gt;as@yahoo.ppp&lt;/Email&gt;
  &lt;Telephone type="string"&gt;0123456789&lt;/Telephone&gt;
  &lt;Comments type="string"&gt;Joint ownership&lt;/Comments&gt;
  &lt;EstimatedMoveDate type="string"&gt;2015-11-25T05:57:00&lt;/EstimatedMoveDate&gt;
  &lt;Charge type="number"&gt;4.99&lt;/Charge&gt;
  &lt;ChargeStatus type="string"&gt;Chargeable&lt;/ChargeStatus&gt;
 &lt;/item&gt;
&lt;/root&gt;
&lt;/OutputSchema&gt;&lt;/NewLeads&gt;&lt;/WebService&gt;


Additionally, object SaleProperty may be missing, instead may be object PurchaseProperty. Similarly, object Quote can contain Sale, Purchase, Remortgage objects or sale and Purchase simultaneously
I can't find any tips on inserting it into one table via xquery on SQL Server 2012. Basic problem is that every time I'm building query to extract even one value (i.e. Transaction) only thing except errors I get is empty string.

my sample query (based on MSDN examples):

SELECT t.c.value('(.)[1]','varchar(50)') as type
from @ixml.nodes('/root/item/transaction') as t(c)


I would like to have an example how to insert this xml into table (where every possible element has it's own column.

I assume that problem is with namespaces and strong typing of the xml. However, this is what I get from web service. I work on xml both missing and containing second xmlns declaration in root element, as well as with structure trimmed down to just root.
The three problems with your XQuery that I can see are (and none of this has anything to do with it being Typed XML):


You are not specifying the correct path to the /root node. It should be:

SELECT t.c.value('(.)[1]','varchar(50)') as type
from @ixml.nodes('/WebService/NewLeads/OutputSchema/root/item/transaction') as t(c)

XML is case-sensitive so you need to use an upper-case "T" for the "Transaction" node:

SELECT t.c.value('(.)[1]','varchar(50)') as type
from @ixml.nodes('/WebService/NewLeads/OutputSchema/root/item/Transaction') as t(c)

While those fixes would probably get you 1 value back (in this case, it should be "SaleOnly"), it won't iterate through the "item" nodes because you were too specific in the path supplied to the .nodes() function. Instead, the final node of that specification should be "item", which is what you want to iterate through. And in that case, you move the "Transaction" part up to the .value() function:

SELECT t.c.value('(./Transaction)[1]','varchar(50)') as type
from @ixml.nodes('/WebService/NewLeads/OutputSchema/root/item') as t(c)



Regarding the statement of:


  I work on xml both missing and containing second xmlns declaration in root element, as well as with structure trimmed down to just root.


The "structure trimmed down to just root" should be handleable by removing everything between the first / and the / right before /root... (i.e. the WebService/NewLeads/OutputSchema). So the resulting path would be:

from @ixml.nodes('//root/item') as t(c)


NOTE:
I am not able to get this to work 100% with the namespace declared in the &lt;WebService&gt; element (please see additional notes as this is no longer the case). Taking that out makes it work. Giving it a prefix, such as xmlns:something="http://www.orbis-software.com/WebSvcCon" makes it work, but then that needs to be declared in the methods.  The only way I can get it to work right now is by declaring the default namespace in each XML function (.nodes and .value) as follows:

SELECT t.c.value('declare default element namespace "http://www.orbis-software.com/WebSvcCon";
                  (./Transaction)[1]','varchar(50)') as [type]
from @ixml.nodes('declare default element namespace "http://www.orbis-software.com/WebSvcCon";
                  /WebService/NewLeads/OutputSchema/root/item') as t(c)


NOTE 2:
Even better, you can use WITH XMLNAMESPACES to declare one or more namespaces to use for the entire query, so no need to define in each XML function. The following both work:

;WITH XMLNAMESPACES (DEFAULT 'http://www.orbis-software.com/WebSvcCon')
SELECT t.c.value('(./Transaction)[1]','varchar(50)') as [type]
from @ixml.nodes('/WebService/NewLeads/OutputSchema/root/item') as t(c)


;WITH XMLNAMESPACES (DEFAULT 'http://www.orbis-software.com/WebSvcCon')
SELECT t.c.value('(./Transaction)[1]','varchar(50)') as [type]
from @ixml.nodes('//root/item') as t(c)


However, just keep in mind that if the document is missing the &lt;WebService xmlns="http://www.orbis-software.com/WebSvcCon"&gt; element and hence has no default namespace, then you need to remove the ;WITH XMLNAMESPACES part. Of course, if the &lt;root&gt; element has its own default namespace, then maybe you will need to keep it. You can play around with it until it works, now that you know the connection between these pieces.

NOTE 3:
If you do end up having two default namespaces declared -- one in the &lt;WebService&gt; element and one in the &lt;root&gt; element -- then you need to specify the URI noted in &lt;root xmlns="bob"&gt; and the // syntax instead of the fully-qualified path.  So if your XML looked like:

&lt;WebService xmlns="http://www.orbis-software.com/WebSvcCon"&gt;
 &lt;NewLeads&gt;
  &lt;OutputSchema&gt;
  &lt;root xmlns="http://someplace" type="array"&gt;


You would then use:

;WITH XMLNAMESPACES (DEFAULT 'http://someplace')
SELECT t.c.value('(./Transaction)[1]','varchar(50)') as [type]
from @ixml.nodes('//root/item') as t(c)


But that won't help if you do have the &lt;WebService&gt; element and yet the &lt;root&gt; element is missing the xmlns declaration. In that case you still need to specify the namespace noted in the &lt;WebService&gt; element. Fun, fun, fun :-).

NOTE 4:
Even more better: incorporating something mentioned in @wBob's answer, we can actually get rid of the ;WITH XMLNAMESPACES clause, and instead use a namespace wildcard. You just need to prefix every node of every XML function with *:. Now the query should look as follows:

SELECT t.c.value('(./*:Transaction)[1]','varchar(50)') AS [type],
       t.c.value('(./*:SaleProperty/*:PostDistrict)[1]','varchar(50)') AS [PostDistrict]
FROM  @ixml.nodes('//*:root/*:item') t(c);


Doing this means that the query works in all of your scenarios:


Full structure starting with "WebService" node, second xmlns declaration:

&lt;WebService xmlns="http://www.orbis-software.com/WebSvcCon"&gt;
  &lt;NewLeads&gt;
    &lt;OutputSchema&gt;
      &lt;root xmlns="uri" type="array"&gt;

Full structure starting with "WebService" node, single xmlns declaration:

&lt;WebService xmlns="http://www.orbis-software.com/WebSvcCon"&gt;
  &lt;NewLeads&gt;
    &lt;OutputSchema&gt;
      &lt;root type="array"&gt;

Trimmed down structure starting with "root" node, single xmlns declaration:

&lt;root xmlns="uri" type="array"&gt;