I have this XML where i want to change the value of 97 in the node 'txtqtyremaining' into a new value. How should i do that?
I don't know how to select to correct node and how to change that value.`
<genxml>
<files />
<hidden />
<textbox>
<txtproductref>SKU</txtproductref>
</textbox>
<dropdownlist />
<checkboxlist />
<radiobuttonlist />
<models>
<genxml>
<files />
<textbox>
<availabledate datatype="date" />
<txtbarcode>BAR1234</txtbarcode>
<txtqtyremaining datatype="double">97</txtqtyremaining>
</textbox>
SET #XML.modify('replace value of (/genxml/models/genxml/textbox/txtqtyremaining[1]/text())[1] with "999.99"')
Select #XML
Or you can use a simple Replace()
Set #XML = Replace(cast(#XML as varchar(max)),'>97</txtqtyremaining>','>999.999</txtqtyremaining>')
Select #XML
Both would Return
<genxml>
<files />
<hidden />
<textbox>
<txtproductref>SKU</txtproductref>
</textbox>
<dropdownlist />
<checkboxlist />
<radiobuttonlist />
<models>
<genxml>
<files />
<textbox>
<availabledate datatype="date" />
<txtbarcode>BAR1234</txtbarcode>
<txtqtyremaining datatype="double">999.999</txtqtyremaining>
</textbox>
</genxml>
</models>
</genxml>
Related
While I am transforming one xml to another and doing mapping list within list elements.I am getting one exception .
"Cannot coerce a :string to a :object (com.mulesoft.weave.mule.exception.WeaveExecutionException). Message payload is of type: WeaveMessageProcessor$WeaveOutputHandler"
Input xml:
<?xml version="1.0" encoding="UTF-8"?>
<ZCOM_IDD2565_AGREEMENT>
<transaction>
<id>www</id>
<timestamp>20160512 200939</timestamp>
<sender>ghh566</sender>
</transaction>
<identification>
<R3number>88898</R3number>
<enterpriseId />
<sourcesystemid>ffff</sourcesystemid>
<sourcesystemobjectid>999089</sourcesystemobjectid>
</identification>
<details>
<newTransaction>N</newTransaction>
<type>siiii</type>
<organizational>
<salesOrg>1223</salesOrg>
<currency>RUPEE</currency>
</organizational>
<description>
<internal>jhjb hjgjhg jkhjh</internal>
<external>jhhgjhb</external>
<project>owdoie</project>
</description>
<dates>
<validFrom>2016-04-05</validFrom>
<validTo>2017-04-30</validTo>
<fixedValue>0000-00-00</fixedValue>
</dates>
<creditTriggerEvent>S</creditTriggerEvent>
</details>
<rules>
<ZCOM_AGR_RULES>
<rule>
<ruleType>923</ruleType>
<agreementItem />
<ruleNumber />
<quantities>
<minimum />
<maximum />
</quantities>
<firstRecordA />
<application />
<conditionType>dddd</conditionType>
<salesOrg>1000</salesOrg>
<distributionChannel />
<division />
<endCustomerNumber />
<serialNumber />
<soldTo>
<ZCOM_AGR_SOLD>
<id>990888</id>
<addressNumber>2132435</addressNumber>
<name>dsfdg fdg</name>
<streetAddress>hu78hj k</streetAddress>
<postalCode>5654</postalCode>
<city>sfds</city>
<country>sdsa</country>
<phone>555-555-5555</phone>
<languageKey>E</languageKey>
<district />
<houseNumber>poio aaed</houseNumber>
<region>iii</region>
</ZCOM_AGR_SOLD>
<ZCOM_AGR_SOLD>
<id>777787</id>
<addressNumber>121223</addressNumber>
<name>dsfdg fdg</name>
<streetAddress>hu78hj k</streetAddress>
<postalCode>5654</postalCode>
<city>sfds</city>
<country>sdsa</country>
<phone>555-555-5555</phone>
<languageKey>E</languageKey>
<district />
<houseNumber>poio aaed</houseNumber>
<region>iii</region>
</ZCOM_AGR_SOLD>
</soldTo>
<shipTo>
<id />
<addressNumber />
<name />
<streetAddress />
<postalCode />
<city />
<country />
<phone />
<languageKey />
<district />
<houseNumber />
<region />
</shipTo>
<upc />
<catalogNumber />
<discountSchedule />
<priceGroupCode />
<priceFamily />
<requested-discount-netPrice />
<delete />
<customerRate />
<priceChange />
<dates>
<validFrom>2016-04-05</validFrom>
<validTo>2017-04-30</validTo>
<fixedValue>0000-00-00</fixedValue>
</dates>
<condition>
<type />
<calculationType />
<approved-discount-netPrice>0.00000</approved-discount-netPrice>
<unitOfMeasue />
<conditionitemindex />
<additionalvaluedays />
<fixedvaluedate />
<maxiumSalesOrdersPerConditionRecord />
<numberOfIncrementalScale />
<scaleNumberForPricing />
</condition>
</rule>
</ZCOM_AGR_RULES>
<ZCOM_AGR_RULES>
<rule>
<ruleType>920</ruleType>
<agreementItem />
<ruleNumber />
<quantities>
<minimum />
<maximum />
</quantities>
<firstRecordA />
<application />
<conditionType>rrrr</conditionType>
<salesOrg>1000</salesOrg>
<distributionChannel />
<division />
<endCustomerNumber />
<serialNumber />
<soldTo />
<shipTo>
<id />
<addressNumber />
<name />
<streetAddress />
<postalCode />
<city />
<country />
<phone />
<languageKey />
<district />
<houseNumber />
<region />
</shipTo>
<upc />
<catalogNumber />
<discountSchedule>B5</discountSchedule>
<priceGroupCode />
<priceFamily />
<requested-discount-netPrice>0.00</requested-discount-netPrice>
<delete />
<customerRate>0.44</customerRate>
<priceChange>X</priceChange>
<dates>
<validFrom>2016-04-05</validFrom>
<validTo>2017-04-30</validTo>
<fixedValue>0000-00-00</fixedValue>
</dates>
<condition>
<type>rrrr</type>
<calculationType>A</calculationType>
<approved-discount-netPrice>0.35000</approved-discount-netPrice>
<unitOfMeasue>%</unitOfMeasue>
<conditionitemindex />
<additionalvaluedays />
<fixedvaluedate />
<maxiumSalesOrdersPerConditionRecord />
<numberOfIncrementalScale />
<scaleNumberForPricing />
</condition>
</rule>
</ZCOM_AGR_RULES>
</rules>
</ZCOM_IDD2565_AGREEMENT>
Data weave script code
%dw 1.0
%output application/xml
%type dtfield = :string { format: "yyyyMMdd" }
%namespace ns0 http://schemas.xmlsoap.org/soap/envelope/
%namespace ns1 FlexiWebService
---
{
ns0#Envelope: {
ns0#Header: {
ns1#AuthHeader: {
Username: "dssdfdf",
Password: "dfff"
}
},
ns0#Body: {
Z_IDDO735_IRM_AGRMNTS01: {
IDOC: {
'_-IRM_-AGMTK01': {
(TRANS: payload.ZCOM_IDD2565_AGREEMENT.details.newTransaction as :string) when payload.ZCOM_IDD2565_AGREEMENT.details.newTransaction?,
(BOART_AG: payload.ZCOM_IDD2565_AGREEMENT.details.type) when payload.ZCOM_IDD2565_AGREEMENT.details.type? ,
(AMTNUM: payload.ZCOM_IDD2565_AGREEMENT.identification.sourcesystemobjectid) when payload.ZCOM_IDD2565_AGREEMENT.identification.sourcesystemobjectid?,
(AGMTNUM_EXT: payload.ZCOM_IDD2565_AGREEMENT.details.description.external as :string) when payload.ZCOM_IDD2565_AGREEMENT.details.description.external?,
(AGMTTXT: payload.ZCOM_IDD2565_AGREEMENT.details.description.internal) when payload.ZCOM_IDD2565_AGREEMENT.details.description.internal?,
(VALID_FROM: payload.ZCOM_IDD2565_AGREEMENT.details.dates.validFrom as :dtfield replace "-" with "") when payload.ZCOM_IDD2565_AGREEMENT.details.dates.validFrom?,
(VALID_TO: payload.ZCOM_IDD2565_AGREEMENT.details.dates.validTo as :dtfield replace "-" with "") when payload.ZCOM_IDD2565_AGREEMENT.details.dates.validTo?,
'_-IRM_-AGMTK02': {
ZIDDO735_AGMTK02: {
(FV_DATE: payload.ZCOM_IDD2565_AGREEMENT.details.dates.fixedValue as :dtfield replace "-" with "") when payload.ZCOM_IDD2565_AGREEMENT.details.dates.fixedValue?,
(TDOBNAME: payload.ZCOM_IDD2565_AGREEMENT.details.creditTriggerEvent) when payload.ZCOM_IDD2565_AGREEMENT.details.creditTriggerEvent?
}
}
},
E1EDK14: {
(ORGID: payload.ZCOM_IDD2565_AGREEMENT.details.organizational.salesOrg) when payload.ZCOM_IDD2565_AGREEMENT.details.organizational.salesOrg?,
ZIDDO735_E1EDK14: {
(CURR: payload.ZCOM_IDD2565_AGREEMENT.details.organizational.currency) when payload.ZCOM_IDD2565_AGREEMENT.details.organizational.currency?
}
},
((payload.ZCOM_IDD2565_AGREEMENT.rules.*ZCOM_AGR_RULES default []) map {
E1KOMG:{
KVEWE: $.rule.firstRecordA,
KOTABNR: $.rule.condition.type,
KAPPL: $.rule.application,
VKORG: $.rule.salesOrg,
VTWEG: $.rule.distributionChannel,
EAN11: $.rule.upc,
KONDM: $.rule.discountSchedule,
EVRTP: $.rule.agreementItem,
HIENR: $.rule.endCustomerNumber,
POSNR: $.rule.ruleNumber,
ANZSN: $.rule.requested-discount-netPrice,
VKGRP: $.rule.priceGroupCode,
ZIDDO735_E1KOMG_QUANTITY: {
TDID_MIN_QTY: $.rule.quantities.minimum,
TDID_MAX_QTY: $.rule.quantities.maximum
},
ZIDDO735_E1KOMG: {
ZIDD0735_SHIP_TO_KUNWE: {
LAND1: $.rule.shipTo.country,
NAME1: $.rule.shipTo.name,
ORT01: $.rule.shipTo.city,
REGIO: $.rule.shipTo.region,
TELF1: $.rule.shipTo.phone as :string replace "-" with "",
ADRNR: $.rule.shipTo.addressNumber,
SPRAS: $.rule.shipTo.languageKey,
STRAS: $.rule.shipTo.streetAddress
},
(ZIDD0735_KNA1_DETAILS: $.rule.soldTo.*ZCOM_AGR_SOLD default [] map {
KUNNR: $.id,
LAND1: $.country,
NAME1: $.name,
ORT01: $.city,
PSTLZ: $.postalCode,
REGIO: $.region,
TELF1: $.phone as :string replace "-" with "",
ADRNR: $.addressNumber,
SPRAS: $.languageKey,
STRAS: $.streetAddress
}) when ($.rule.soldTo !="" and $.rule.soldTo.*ZCOM_AGR_SOLD as :object !="")
},
E1KONH: {
DATAB: $.rule.dates.validFrom as :dtfield replace "-" with "",
DATBI: $.rule.dates.validTo as :dtfield replace "-" with "",
E1KONP: {
KSCHL: $.rule.conditionType,
KRECH: $.rule.condition.calculationType,
KBETR: $.rule.condition.approved-discount-netPrice,
KONWA: $.rule.condition.unitOfMeasue,
ZAEHK_IND: $.rule.condition.conditionitemindex,
VALTG: $.rule.condition.additionalvaluedays,
VALDT: $.rule.condition.fixedvaluedate,
KLF_STG: $.rule.condition.numberOfIncrementalScale,
KLF_KAL: $.rule.condition.scaleNumberForPricing
}
}
}})
}
}
}
}
}
Actually what is happening, fields under ZIDD0735_KNA1_DETAILS-node of output xml is mapped to fields under ZCOM_AGR_SOLD and ZCOM_AGR_SOLD is List of data or you can say array.In output where I have values for ZCOM_AGR_SOLD, I am getting data under ZIDD0735_KNA1_DETAILS, but instead of the repeated values of ZIDD0735_KNA1_DETAILS I am getting ZCOM_AGR_SOLD under ZIDD0735_KNA1_DETAILS with all input xml node names not output node names.This is happening with this field only. rest everything is working fine.
This is a similar scenario:
https://forums.mulesoft.com/questions/1108/dataweave-date-conversion-from-string.html
Could it be that your dates are the one causing the exception?
My XML looks like
<?xml version="1.0" encoding="UTF-8"?>
<ListasExternasFull xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Encabezado xmlns="http://tempuri.org/">
<Acceso>true</Acceso>
<Usuario>FENALCO</Usuario>
<Contrasena>FENALCO2015PROD</Contrasena>
<Documento>24944511</Documento>
<TipoDocumento>1</TipoDocumento>
<Nombres />
<Apellidos />
<Login />
<Fecha>2016-01-23T17:07:56.1986626-05:00</Fecha>
<IdConsulta>0</IdConsulta>
</Encabezado>
<objContraloria xmlns="http://tempuri.org/">
<Id>92798</Id>
<IsContraloria>false</IsContraloria>
<Cedula>24944511</Cedula>
<Nombre />
<Departamento />
<Municipio />
<EntidadAfectada />
<FallosACargo />
<TipoResponsabilidad />
<TipoPersona />
<ReportadoPor />
<FechaControl>2016-01-23T17:03:43.13</FechaControl>
<Excepcion />
</objContraloria>
<objFosyga xmlns="http://tempuri.org/">
<Id>92496</Id>
<IsFosyga>false</IsFosyga>
<NumeroIdentidad>24944511</NumeroIdentidad>
<Nombre />
<Apellido />
<Departamento />
<Municipio />
<Estado />
<Entidad />
<Regimen />
<FechaAfiliacion />
<TipoAfiliado />
<FechaControl>2016-01-23T17:07:56.285612-05:00</FechaControl>
<Excepcion>Se generó un error al consultar la lista. Por favor intente mas tarde o contacte a su administrador.</Excepcion>
</objFosyga>
<objOfac xmlns="http://tempuri.org/">
<Id>91950</Id>
<Cedula>24944511</Cedula>
<Nombre />
<Direccion />
<Tipo />
<Programa />
<Score />
<FechaControl>2016-01-23T17:03:43.097</FechaControl>
<Lista />
<Excepcion />
<IsOfac>false</IsOfac>
</objOfac>
<objPolicia xmlns="http://tempuri.org/">
<Id>93113</Id>
<Cedula>24944511</Cedula>
<Nombre />
<IsAntecedentes>false</IsAntecedentes>
<IsRegistrado>false</IsRegistrado>
<Mensaje />
<FechaControl>2016-01-23T17:08:17.3118339-05:00</FechaControl>
<IsPolicia>false</IsPolicia>
<Excepcion>Se generó un error al consultar la lista. Por favor intente mas tarde o contacte a su administrador.</Excepcion>
</objPolicia>
<objRues xmlns="http://tempuri.org/">
<Id>91297</Id>
<TipoID />
<Nit>24944511</Nit>
<RazonSocial />
<Descripcion_Camara />
<Descripcion_Categoria_Matricula />
<Fecha_Matricula />
<IsRM>false</IsRM>
<IsRUP>false</IsRUP>
<IsESAL>false</IsESAL>
<IsRNT>false</IsRNT>
<FechaControl>2016-01-23T17:03:43.473</FechaControl>
<IsRUES>false</IsRUES>
<Excepcion />
</objRues>
<objSim xmlns="http://tempuri.org/">
<Id>92657</Id>
<Cedula>24944511</Cedula>
<NoRadicado />
<Identificador />
<FechaSolicitud />
<Estado />
<Resultado />
<DisponibleEntrega />
<Excepcion />
<FechaControl>2016-01-23T17:03:43.207</FechaControl>
<IsSim>false</IsSim>
</objSim>
<objSimit xmlns="http://tempuri.org/">
<Id>92905</Id>
<Cedula>24944511</Cedula>
<Infractor />
<Resolucion />
<FechaResolucion />
<Comparendo />
<FechaComparendo />
<Secretaria />
<Estado />
<Infraccion />
<ValorMulta />
<InteresMora />
<ValorAdicional />
<ValorPagar />
<FechaControl>2016-01-23T17:03:43.55</FechaControl>
<IsSimit>false</IsSimit>
<Excepcion />
</objSimit>
<objSisben xmlns="http://tempuri.org/">
<Id>94783</Id>
<IsSisben>true</IsSisben>
<NumeroDocumento>24944511</NumeroDocumento>
<Nombres>MARIA ISLENY</Nombres>
<Apellidos>RODAS DE FRANCO</Apellidos>
<TipoDocumento>Cédula de Ciudadanía</TipoDocumento>
<Departamento>RISARALDA</Departamento>
<Municipio>PEREIRA</Municipio>
<Area>1</Area>
<Ficha>10097</Ficha>
<Puntaje>47,86</Puntaje>
<FechaModificacion>2015/03/05</FechaModificacion>
<Estado>VALIDADO</Estado>
<FechaControl>2016-01-23T17:03:43.287</FechaControl>
<Excepcion />
</objSisben>
<objRuaf xmlns="http://tempuri.org/">
<Id>84066</Id>
<IsRuaf>true</IsRuaf>
<TipoIdentificacion>CC</TipoIdentificacion>
<Identificacion>24944511</Identificacion>
<Nombre>MARIA ISLENY RODAS DE FRANCO</Nombre>
<Sexo>FEMENINO</Sexo>
<UbicacionAfiliacion>RISARALDA - PEREIRA</UbicacionAfiliacion>
<EstadoAfiliado>ACTIVO</EstadoAfiliado>
<Administradora>NUEVA EPS SA</Administradora>
<Regimen>SALUD: CONTRIBUTIVO</Regimen>
<FechaAfiliacion>2015-08-01</FechaAfiliacion>
<TipoAfiliado>BENEFICIARIO</TipoAfiliado>
<FechaControl>2016-01-23T17:03:45.207</FechaControl>
<Observacion />
<Excepcion />
</objRuaf>
<objDisponibilidad xmlns="http://tempuri.org/">
<Fosyga>true</Fosyga>
<Sisben>true</Sisben>
<Ofac>true</Ofac>
<Policia>true</Policia>
<Rues>true</Rues>
<Sim>true</Sim>
<Simit>true</Simit>
<Contraloria>true</Contraloria>
<Onu>true</Onu>
<Ruaf>true</Ruaf>
</objDisponibilidad>
</ListasExternasFull>
and I can not get reach to consult the objRuaf/Identificacion node due to nested namespaces aguin I can help with a query to reach these nodes
Declare default XML namespace WITH XMLNAMESPACES (DEFAULT 'http://tempuri.org/'):
;WITH XMLNAMESPACES (DEFAULT 'http://tempuri.org/')
SELECT val = s.c.value('.', 'NVARCHAR(100)')
FROM #x.nodes('//objRuaf/Identificacion') AS s(c);
LiveDemo
Or:
;WITH XMLNAMESPACES ('http://tempuri.org/' AS a)
SELECT val = s.c.value('.', 'NVARCHAR(100)')
FROM #x.nodes('//a:objRuaf/a:Identificacion') AS s(c)
Can you all help me for this problem?
I want to get value from following XML in sql stored procedure. I don't get vlaue if 'xsi:type="ActiveDirectoryItem"' is in tag 'anyType', and 'ActiveDirectoryItems' tag is also with URLs. How can i do to get only values?
<?xml version="1.0" encoding="utf-8" ?>
<ActiveDirectoryItems xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Items>
<anyType xsi:type="ActiveDirectoryItem">
<FirstName />
<MiddleInitial />
<LastName />
<DisplayName>Migrate-group</DisplayName>
<UserPrincipalName />
<PostalAddress />
<ResidentialAddress />
<Title />
<HomePhone />
<OfficePhone />
<Mobile />
<Fax />
<Email>Migrate-group#gmail.com</Email>
<Url />
<AccountName>Migrate-group</AccountName>
<DistinguishedName />
<IsAccountActive>false</IsAccountActive>
<ManagedBy />
<Manager />
<CompareType>0</CompareType>
<Description />
<Department />
<Company />
<Type />
</anyType>
</Items>
<GlobalCatalog />
</ActiveDirectoryItems>
The format i want to get is as the following:
DisplayName Email Account Name
Migrate-group Migrate-group#gmail.com Migrate-group
you can use the value keyword
Example:
DECLARE #MyXml XML = '<Root><SomeData>100</SomeData></Root>'
DECLARE #Something INT
SELECT #Something = #MyXml.value('(//Root/SomeData)[1]', 'INT')
I am trying to join the two xml response in stored procedure with the below mentioned code .The output that i was looking from my select query was
declare #cdoValuation xml
declare #marketColorPrice xml
set #cdoValuation = '<Response>
<CDOValuation id="BAB12-II.A2" mv="1.019358126500000e+002" run_date="2014-04-30T00:00:00" />
<CDOValuation id="BABS12-I.C" mv="9.915358793000000e+001" run_date="2014-04-30T00:00:00" />
<CDOValuation id="BLUEMTN.A2" mv="9.925446292000000e+001" run_date="2014-04-30T00:00:00" />
<CDOValuation id="BLUEMTN3.C" mv="9.472908099999999e+001" run_date="2014-04-30T00:00:00" />
<CDOValuation id="CGMS11-1.D" mv="9.644486014000000e+001" run_date="2014-04-30T00:00:00" />
<CDOValuation id="CSQUARE4.A" mv="9.880319818000000e+001" run_date="2014-04-30T00:00:00" />
<CDOValuation id="CSQUARE4.C" mv="9.295238056000000e+001" run_date="2014-04-30T00:00:00" />
<CDOValuation id="MADPK5.C" mv="9.735145883000000e+001" run_date="2014-04-30T00:00:00" />
<CDOValuation id="MADPK7.PS" mv="9.225345985000000e+001" run_date="2014-04-30T00:00:00" />
<CDOValuation id="MADPK8.A" mv="9.984445828000000e+001" run_date="2014-04-30T00:00:00" />
<CDOValuation id="OHAPARK.B" mv="9.652910265000000e+001" run_date="2014-04-30T00:00:00" />
<CDOValuation id="SDAYTONA.B2L" mv="9.590162241000000e+001" run_date="2014-04-30T00:00:00" />
</Response>'
set #marketColorPrice = '<Response>
<MarketColorPrice tranche_id="BAB12-II.A2" mk_price="1.001533333333333e+002" mk_date="2013-12-19T00:00:00" mk_source1="Empirasign/SCI" mk_source2="Cvr, Talk" mk_record_type="bwic, pxtalk" />
<MarketColorPrice tranche_id="BLUEMTN.A2" mk_price="9.877000000000000e+001" mk_date="2013-12-16T00:00:00" mk_source1="Empirasign/SCI" mk_source2="Cvr, Talk" mk_record_type="bwic, pxtalk" />
<MarketColorPrice tranche_id="BLUEMTN3.C" mk_price="8.050000000000000e+001" mk_date="2013-05-15T00:00:00" mk_source1="Empirasign/SCI" mk_source2="Talk, Trade" mk_record_type="bwic, pxtalk" />
<MarketColorPrice tranche_id="CSQUARE4.A" mk_price="9.765294117647059e+001" mk_date="2014-04-08T00:00:00" mk_source1="Empirasign/SCI" mk_source2="Cvr, Talk" mk_record_type="bwic, pxtalk" />
<MarketColorPrice tranche_id="CSQUARE4.C" mk_price="9.125000000000000e+001" mk_date="2014-05-15T00:00:00" mk_source1="Empirasign" mk_source2="Talk" mk_record_type="market" />
<MarketColorPrice tranche_id="MADPK5.C" mk_price="9.200000000000000e+001" mk_date="2013-10-24T00:00:00" mk_source1="SCI" mk_source2="Cvr" />
<MarketColorPrice tranche_id="MADPK7.PS" mk_price="1.133333333333333e+002" mk_date="2013-08-28T00:00:00" mk_source1="Empirasign/SCI" mk_source2="Cvr, Talk" mk_record_type="bwic, pxtalk" />
<MarketColorPrice tranche_id="OHAPARK.B" mk_price="9.787500000000000e+001" mk_date="2014-04-21T00:00:00" mk_source1="Empirasign" mk_source2="Talk" mk_record_type="market" />
</Response>'
declare #responseXml xml
set #responseXml =(select cdoValuation.cdoValuationcol.value('(//CDOValuation/#mv)[1]', 'float') as "#mv",
dbo.ToShortDateString(cdoValuation.cdoValuationcol.value('(//CDOValuation/#run_date)[1]', 'datetime')) as "#run_date",
marketColorPrice.marketColorPricecol.value('(//MarketColorPrice/#mk_price)[1]', 'float') as "#mk_price",
marketColorPrice.marketColorPricecol.value('(//MarketColorPrice/#mk_source1)[1]', 'varchar(30)') as "#mk_source1",
marketColorPrice.marketColorPricecol.value('(//MarketColorPrice/#mk_source2)[1]', 'varchar(30)') as "#mk_source2"
from #cdoValuation.nodes('/CDOValuation') cdoValuation(cdoValuationcol)
inner join #marketColorPrice.nodes('/MarketColorPrice') marketColorPrice(marketColorPricecol)
on marketColorPrice.marketColorPricecol.value('(//MarketColorPrice/tranche_id)[1]', 'VARCHAR(20)') =
cdoValuation.cdoValuationcol.value('(//CDOValuation/id)[1]', 'VARCHAR(20)') FOR XML PATH('BWICResult')
, ROOT('Response'))
select #responseXml
The output that i was expecting was of the following format but
doesnt seems to be the case .Can someone help me out to know as to what should be done ?
<Response> <BWICResult tranche_id="BAB12-II.A2" mv="1.019358126500000e+002" mk_price="1.001533333333333e+002"/> <BWICResult tranche_id="BLUEMTN.A2" mv="9.925446292000000e+001" mk_price="9.877000000000000e+001"/> </Response>
select C.X.value('#id', 'varchar(20)') as '#id',
C.X.value('#mv', 'float') as '#mv',
M.X.value('#mk_price', 'float') as '#mk_price'
from #cdoValuation.nodes('/Response/CDOValuation') as C(X)
inner join #marketColorPrice.nodes('Response/MarketColorPrice') as M(X)
on C.X.value('#id', 'varchar(20)') = M.X.value('#tranche_id', 'varchar(20)')
for xml path('BWICResult'), root('Response')
Result:
<Response>
<BWICResult id="BAB12-II.A2" mv="1.019358126500000e+002" mk_price="1.001533333333333e+002" />
<BWICResult id="BLUEMTN.A2" mv="9.925446292000000e+001" mk_price="9.877000000000000e+001" />
<BWICResult id="BLUEMTN3.C" mv="9.472908099999999e+001" mk_price="8.050000000000000e+001" />
<BWICResult id="CSQUARE4.A" mv="9.880319818000000e+001" mk_price="9.765294117647059e+001" />
<BWICResult id="CSQUARE4.C" mv="9.295238056000000e+001" mk_price="9.125000000000000e+001" />
<BWICResult id="MADPK5.C" mv="9.735145883000000e+001" mk_price="9.200000000000000e+001" />
<BWICResult id="MADPK7.PS" mv="9.225345985000000e+001" mk_price="1.133333333333333e+002" />
<BWICResult id="OHAPARK.B" mv="9.652910265000000e+001" mk_price="9.787500000000000e+001" />
</Response>
What is the correct way to remove all child nodes of the root node with a missing attribute from an xml field in Sql Server 2008?
My Xml looks like this, I want to remove all the child nodes of <root> that don't have the ln attribute specified
<root>
<title />
<title />
<questionphrase ln="nl">
<xhtml />
</questionphrase>
<questionphrase ln="en">
<xhtml />
</questionphrase>
<information ln="nl">
<xhtml />
</information>
<information ln="en">
<xhtml />
</information>
<title />
<title ln="en">
value
</title>
<label ln="en">
value
</label>
<title />
<title />
</root>
After the delete the xml should look like this
<root>
<questionphrase ln="nl">
<xhtml />
</questionphrase>
<questionphrase ln="en">
<xhtml />
</questionphrase>
<information ln="nl">
<xhtml />
</information>
<information ln="en">
<xhtml />
</information>
<title ln="en">
value
</title>
<label ln="en">
value
</label>
</root>
Try this:
DECLARE #xml XML = '....'
SET #xml.modify('delete //root/*[not(#ln)]')
SQL FIDDLE DEMO