select multiple nodes xml - sql-server

I'm retrieving xml formatted text from ntext fields (sample format of a row below):
<root>
<DocInfo>
<CompanyName>Some Company</CompanyName>
<WebsiteUrl>http://www.someurl.com</WebsiteUrl>
<PrimaryServices>Benefits Administration</PrimaryServices>
<PrimaryServices>Payroll Processing</PrimaryServices>
<SecondaryServices>Background Checking</SecondaryServices>
<SecondaryServices>HR Outsourcing</SecondaryServices>
<SecondaryServices>Comp & Benefits</SecondaryServices>
<SecondaryServices>Administration</SecondaryServices>
</DocInfo>
</root>
Using this sql I am retrieving the single node values:
select #xmlString = COALESCE(#xmlString + '', '') + cast(content_html as nvarchar(max)) FROM content where folder_id = 18
set #xmlString = replace(#xmlString,'<?xml version="1.0" encoding="UTF-16" standalone="yes"?>','')
set #XML = cast(#xmlString as xml)
Select
T.N.value('CompanyName[1]', 'varchar(250)') as CompanyName,
T.N.value('WebsiteUrl[1]', 'varchar(250)') as WebsiteUrl,
T.N.value('PrimaryServices[1]', 'varchar(250)') as PrimaryServices,
T.N.value('SecondaryServices[1]', 'varchar(250)') as SecondaryServices,
T.N.value('Description[1]', 'varchar(max)') as Description
from #XML.nodes('/root/DocInfo') as T(N)
This works fine for the single node values (CompanyName, WebsiteUrl). However, it isn't inserting the nodes with multiple values properly (like PrimaryServices and SecondaryServices - each of which may have zero to 16 nodes). How do I get these variable length multiple node values into these columns?
Thanks for any help

To get the multiple nodes as a comma separated value you can use a variant of the for xml path('') trick. Use the shredded XML (T.N) as a source in the sub-query to get the nodes you are interested in. The xQuery ... substring(text()[1]) ... part is just there to remove the extra comma and to get the comma separated value out of the XML that is created by for xml.
select
T.N.value('(CompanyName/text())[1]', 'varchar(250)') as CompanyName,
T.N.value('(WebsiteUrl/text())[1]', 'varchar(250)') as WebsiteUrl,
(
select ', '+P.N.value('text()[1]', 'varchar(max)')
from T.N.nodes('PrimaryServices') as P(N)
for xml path(''), type
).value('substring(text()[1], 2)', 'varchar(max)') as PrimaryServices,
(
select ', '+S.N.value('text()[1]', 'varchar(max)')
from T.N.nodes('SecondaryServices') as S(N)
for xml path(''), type
).value('substring(text()[1], 2)', 'varchar(max)') as SecondaryServices,
T.N.value('(Description/text())[1]', 'varchar(max)') as Description
from #XML.nodes('/root/DocInfo') as T(N)
If you want all the services in one column you can use a different xPath in the nodes part in the sub-query.
select
T.N.value('(CompanyName/text())[1]', 'varchar(250)') as CompanyName,
T.N.value('(WebsiteUrl/text())[1]', 'varchar(250)') as WebsiteUrl,
(
select ', '+P.N.value('text()[1]', 'varchar(max)')
from T.N.nodes('PrimaryServices,SecondaryServices') as P(N)
for xml path(''), type
).value('substring(text()[1], 2)', 'varchar(max)') as Services,
T.N.value('(Description/text())[1]', 'varchar(max)') as Description
from #XML.nodes('/root/DocInfo') as T(N)

Related

T-SQL wildcard search all values in comma delimited variable

I want to get matching record with all values in the variables.
e.g., 001, 3
Should return record that has 001 and 3 in their UnitId.
What is wrong with my statement? It only returns the matching record for the first item in comma delimited variable.
DECLARE #SearchTags AS VARCHAR(MAX) = '001, 3';
SELECT
Asset.UnitId, Asset.Description
FROM
Asset
WHERE
EXISTS (SELECT Split.XMLString.value('.', 'NVARCHAR(MAX)')
FROM
(SELECT CAST('<X>'+REPLACE(#SearchTags, ',', '</X><X>')+'</X>' AS XML) AS [XML]) AS XMLString
CROSS APPLY
[XML].nodes('/X') AS Split(XMLString)
WHERE
Asset.UnitId LIKE '%' + Split.XMLString.value('.', 'NVARCHAR(MAX)') + '%'
)
SQL Fiddle

SQL Server Split using XML - illegal name character

I am using the following to spilt comma separated string into columns (SQL Server 2014):
function [dbo].[splitString](#input Varchar(max), #Splitter Varchar(99)) returns table as
Return
SELECT Split.a.value('.', 'NVARCHAR(max)') AS Data FROM
( SELECT CAST ('<M>' + REPLACE(#input, #Splitter, '</M><M>') + '</M>' AS XML) AS Data
) AS A CROSS APPLY Data.nodes ('/M') AS Split(a);
When I try to split the following:
Front Office,Food & Beverage,Housekeeping,Human Resource & Training,Reservation,Other
I get the following error: XML parsing: line 1, character 82, illegal name character
Is there a way to include special characters in my function?
Please try the following solution.
Notable points:
CData section protects against XML entities like ampersand and the
like.
text() inside .nodes() method is for performance reasons.
TRY_CAST() will return NULL, but will not error out.
SQL
DECLARE #input Varchar(max) = 'Front Office,Food & Beverage,Housekeeping,Human Resource & Training,Reservation,Other'
, #Splitter Varchar(99) = ',';
SELECT Split.a.value('.', 'NVARCHAR(max)') AS Data
FROM ( SELECT TRY_CAST('<M><![CDATA[' + REPLACE(#input, #Splitter, ']]></M><M><![CDATA[') + ']]></M>' AS XML) AS Data
) AS A CROSS APPLY Data.nodes ('/M/text()') AS Split(a);

How to join element values in XQuery for SQL Server?

If I have this XML
<TradingInquirySearchResult xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SearchTerm>test</SearchTerm>
<CompanyFound>true</CompanyFound>
<CompanyInfoCollection>
<CompanyInfo>
<CompanyID>26</CompanyID>
<CompanyName>test</CompanyName>
<Status>Unrestricted</Status>
<SearchTags>
<Tag>test2</Tag>
<Tag>test3</Tag>
<Tag>test4</Tag>
</SearchTags>
</CompanyInfo>
</CompanyInfoCollection>
</TradingInquirySearchResult>
I want to get "test2;test3;test4". How can I join the values of <Tag> for the first <CompanyInfo> tag?
I tried TransactionData.value('(/TradingInquirySearchResult/CompanyInfoCollection/CompanyInfo[1]/SearchTags/Tag)[1]', 'nvarchar(1000)')
but it didn't work.
Thanks
As you're using SQL Server 2012 (or rather not 2017+) the common way to aggregate strings is to use FOR XML PATH and STUFF, and you can get the multiple values for the node Tag using the nodes operator. This gives you the below:
DECLARE #XML xml = '
<TradingInquirySearchResult xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SearchTerm>test</SearchTerm>
<CompanyFound>true</CompanyFound>
<CompanyInfoCollection>
<CompanyInfo>
<CompanyID>26</CompanyID>
<CompanyName>test</CompanyName>
<Status>Unrestricted</Status>
<SearchTags>
<Tag>test2</Tag>
<Tag>test3</Tag>
<Tag>test4</Tag>
</SearchTags>
</CompanyInfo>
</CompanyInfoCollection>
</TradingInquirySearchResult>';
SELECT STUFF((SELECT N';' + ST.Tag.value('(./text())[1]','nvarchar(100)')
FROM (VALUES(#XML))V(X)
CROSS APPLY V.X.nodes('/TradingInquirySearchResult/CompanyInfoCollection/CompanyInfo/SearchTags/Tag') ST(Tag)
FOR XML PATH(N''),TYPE).value('.','nvarchar(MAX)'),1,1,N'') AS Tags
Edit for guess when multiple companies.
If you only want the first company, then yes, using [1] would work:
DECLARE #XML xml = '
<TradingInquirySearchResult xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SearchTerm>test</SearchTerm>
<CompanyFound>true</CompanyFound>
<CompanyInfoCollection>
<CompanyInfo>
<CompanyID>26</CompanyID>
<CompanyName>test</CompanyName>
<Status>Unrestricted</Status>
<SearchTags>
<Tag>test2</Tag>
<Tag>test3</Tag>
<Tag>test4</Tag>
</SearchTags>
</CompanyInfo>
<CompanyInfo>
<CompanyID>27</CompanyID>
<CompanyName>Sample</CompanyName>
<Status>Restricted</Status>
<SearchTags>
<Tag>test6</Tag>
<Tag>test7</Tag>
<Tag>test8</Tag>
</SearchTags>
</CompanyInfo>
</CompanyInfoCollection>
</TradingInquirySearchResult>';
SELECT STUFF((SELECT N';' + ST.Tag.value('(./text())[1]','nvarchar(100)')
FROM (VALUES(#XML))V(X)
CROSS APPLY V.X.nodes('/TradingInquirySearchResult/CompanyInfoCollection/CompanyInfo[1]/SearchTags/Tag') ST(Tag)
FOR XML PATH(N''),TYPE).value('.','nvarchar(MAX)'),1,1,N'') AS Tags;
If, however, you want a row per company, then you would want to do something like this:
SELECT CIC.CI.value('(./CompanyID/text())[1]','nvarchar(50)') AS CompanyID,
STUFF((SELECT N';' + ST.Tag.value('(./text())[1]','nvarchar(100)')
FROM CIC.CI.nodes('./SearchTags/Tag') ST(Tag)
FOR XML PATH(N''),TYPE).value('.','nvarchar(MAX)'),1,1,N'') AS Tags
FROM (VALUES(#XML))V(X)
CROSS APPLY V.X.nodes('/TradingInquirySearchResult/CompanyInfoCollection/CompanyInfo') CIC(CI);

How to query for Xml values and attributes from table in SQL Server?

I have a table that contains a Xml column:
SELECT *
FROM Sqm
A sample of the xml data of a row would be:
<Sqm version="1.2">
<Metrics>
<Metric id="TransactionCleanupThread.RecordUsedTransactionShift" type="timer" unit="µs" count="1" sum="21490" average="21490" minValue="73701" maxValue="73701" >73701</Metric>
<Metric id="TransactionCleanupThread.RefundOldTrans" type="timer" unit="µs" count="1" sum="184487" average="184487" minValue="632704" maxValue="632704" >632704</Metric>
<Metric id="Database.CreateConnection_SaveContextUserGUID" type="timer" unit="µs" count="2" sum="7562" average="3781" minValue="12928" maxValue="13006" standardDeviation="16" >12967</Metric>
<Metric id="Global.CurrentUser" type="timer" unit="µs" count="6" sum="4022464" average="670411" minValue="15" maxValue="13794345" standardDeviation="1642047">2299194</Metric>
<Metric id="Global.CurrentUser_FetchIdentityFromDatabase" type="timer" unit="µs" count="1" sum="4010057" average="4010057" minValue="13752614" maxValue="13752614" >13752614</Metric>
</Metrics>
</Sqm>
In the case of this data, I would want:
SqmId id type unit count sum minValue maxValue standardDeviation Value
===== =================================================== ===== ==== ===== ====== ======== ======== ================= ======
1 TransactionCleanupThread.RecordUsedTransactionShift timer µs 1 21490 73701 73701 NULL 73701
1 TransactionCleanupThread.RefundOldTrans timer µs 1 184487 632704 632704 NULL 632704
1 Database.CreateConnection_SaveContextUserGUID timer µs 2 7562 12928 13006 16 12967
1 Global.CurrentUser timer µs 6 4022464 15 13794345 1642047 2299194
1 Global.CurrentUser_FetchIdentityFromDatabase timer µs 1 4010057 13752614 13752614 NULL 13752614
2 ...
In the end I'll actually be performing SUM(), MIN(), MAX() aggregation. But for now I'm just trying to query an xml column.
In pseudo-code, I would try something like:
SELECT
SqmId,
Data.query('/Sqm/Metrics/Metric/#id') AS id,
Data.query('/Sqm/Metrics/Metric/#type') AS type,
Data.query('/Sqm/Metrics/Metric/#unit') AS unit,
Data.query('/Sqm/Metrics/Metric/#sum') AS sum,
Data.query('/Sqm/Metrics/Metric/#count') AS count,
Data.query('/Sqm/Metrics/Metric/#minValue') AS minValue,
Data.query('/Sqm/Metrics/Metric/#maxValue') AS maxValue,
Data.query('/Sqm/Metrics/Metric/#standardDeviation') AS standardDeviation,
Data.query('/Sqm/Metrics/Metric') AS value
FROM Sqm
But that SQL query doesn't work:
Msg 2396, Level 16, State 1, Line 2
XQuery [Sqm.data.query()]: Attribute may not appear outside of an element
I've hunted, and it's amazing how poorly documented, or exampled, Xml querying is. Most resources rather than querying a table, query a variable; which I'm not doing. Most resources only use xml querying for filtering and selection, rather than reading values. Most resources read hard-coded child nodes (by index), rather than actual values.
Related resources that I read
https://stackoverflow.com/questions/966441/xml-query-in-sql-server-2008
SQL Server query xml attribute for an element value
SQL querying XML attributes
SQL Server 2005 XQuery and XML-DML - Part 1
BOL: XML Support in Microsoft SQL Server 2005
Querying XML in SQL Server
Basic SQL Server XML Querying
BOL: query() Method (xml Data Type)
XML Workshop V - Reading Values from XML Columns
SQL SERVER – Introduction to Discovering XML Data Type Methods – A Primer
Update: .value rather than .query
I tried randomly using .value, in place of .query:
SELECT
Sqm.SqmId,
Data.value('/Sqm/Metrics/Metric/#id', 'varchar(max)') AS id,
Data.value('/Sqm/Metrics/Metric/#type', 'varchar(max)') AS type,
Data.value('/Sqm/Metrics/Metric/#unit', 'varchar(max)') AS unit,
Data.value('/Sqm/Metrics/Metric/#sum', 'varchar(max)') AS sum,
Data.value('/Sqm/Metrics/Metric/#count', 'varchar(max)') AS count,
Data.value('/Sqm/Metrics/Metric/#minValue', 'varchar(max)') AS minValue,
Data.value('/Sqm/Metrics/Metric/#maxValue', 'varchar(max)') AS maxValue,
Data.value('/Sqm/Metrics/Metric/#standardDeviation', 'varchar(max)') AS standardDeviation,
Data.value('/Sqm/Metrics/Metric', 'varchar(max)') AS value
FROM Sqm
But that also doesn't work:
Msg 2389, Level 16, State 1, Line 3 XQuery [Sqm.data.value()]:
'value()' requires a singleton (or empty sequence), found operand of
type 'xdt:untypedAtomic *'
Actually you're close to your goal, you just need to use nodes() method to split your rows and then get values:
select
s.SqmId,
m.c.value('#id', 'varchar(max)') as id,
m.c.value('#type', 'varchar(max)') as type,
m.c.value('#unit', 'varchar(max)') as unit,
m.c.value('#sum', 'varchar(max)') as [sum],
m.c.value('#count', 'varchar(max)') as [count],
m.c.value('#minValue', 'varchar(max)') as minValue,
m.c.value('#maxValue', 'varchar(max)') as maxValue,
m.c.value('.', 'nvarchar(max)') as Value,
m.c.value('(text())[1]', 'nvarchar(max)') as Value2
from sqm as s
outer apply s.data.nodes('Sqm/Metrics/Metric') as m(c)
sql fiddle demo
I've been trying to do something very similar but not using the nodes. However, my xml structure is a little different.
You have it like this:
<Metrics>
<Metric id="TransactionCleanupThread.RefundOldTrans" type="timer" ...>
If it were like this instead:
<Metrics>
<Metric>
<id>TransactionCleanupThread.RefundOldTrans</id>
<type>timer</type>
.
.
.
Then you could simply use this SQL statement.
SELECT
Sqm.SqmId,
Data.value('(/Sqm/Metrics/Metric/id)[1]', 'varchar(max)') as id,
Data.value('(/Sqm/Metrics/Metric/type)[1]', 'varchar(max)') AS type,
Data.value('(/Sqm/Metrics/Metric/unit)[1]', 'varchar(max)') AS unit,
Data.value('(/Sqm/Metrics/Metric/sum)[1]', 'varchar(max)') AS sum,
Data.value('(/Sqm/Metrics/Metric/count)[1]', 'varchar(max)') AS count,
Data.value('(/Sqm/Metrics/Metric/minValue)[1]', 'varchar(max)') AS minValue,
Data.value('(/Sqm/Metrics/Metric/maxValue)[1]', 'varchar(max)') AS maxValue,
Data.value('(/Sqm/Metrics/Metric/stdDeviation)[1]', 'varchar(max)') AS stdDeviation,
FROM Sqm
To me this is much less confusing than using the outer apply or cross apply.
I hope this helps someone else looking for a simpler solution!
use value instead of query (must specify index of node to return in the XQuery as well as passing the sql data type to return as the second parameter):
select
xt.Id
, x.m.value( '#id[1]', 'varchar(max)' ) MetricId
from
XmlTest xt
cross apply xt.XmlData.nodes( '/Sqm/Metrics/Metric' ) x(m)
I don't understand why some people are suggesting using cross apply or outer apply to convert the xml into a table of values. For me, that just brought back way too much data.
Here's my example of how you'd create an xml object, then turn it into a table.
(I've added spaces in my xml string, just to make it easier to read.)
DECLARE #str nvarchar(2000)
SET #str = ''
SET #str = #str + '<users>'
SET #str = #str + ' <user>'
SET #str = #str + ' <firstName>Mike</firstName>'
SET #str = #str + ' <lastName>Gledhill</lastName>'
SET #str = #str + ' <age>31</age>'
SET #str = #str + ' </user>'
SET #str = #str + ' <user>'
SET #str = #str + ' <firstName>Mark</firstName>'
SET #str = #str + ' <lastName>Stevens</lastName>'
SET #str = #str + ' <age>42</age>'
SET #str = #str + ' </user>'
SET #str = #str + ' <user>'
SET #str = #str + ' <firstName>Sarah</firstName>'
SET #str = #str + ' <lastName>Brown</lastName>'
SET #str = #str + ' <age>23</age>'
SET #str = #str + ' </user>'
SET #str = #str + '</users>'
DECLARE #xml xml
SELECT #xml = CAST(CAST(#str AS VARBINARY(MAX)) AS XML)
-- Iterate through each of the "users\user" records in our XML
SELECT
x.Rec.query('./firstName').value('.', 'nvarchar(2000)') AS 'FirstName',
x.Rec.query('./lastName').value('.', 'nvarchar(2000)') AS 'LastName',
x.Rec.query('./age').value('.', 'int') AS 'Age'
FROM #xml.nodes('/users/user') as x(Rec)
And here's the output:

Concatenate XML without type casting to string

I have the following XML generated from various tables in my SQL SERVER database
<XMLData>
...
<Type>1</Type>
...
</XMLData>
AND
<XMLData>
...
<Type>2</Type>
...
</XMLData>
AND
<XMLData>
...
<Type>3</Type>
...
</XMLData>
The final output I need is single combined as follows:
<AllMyData>
<XMLData>
...
<Type>1</Type>
...
</XMLData>
<XMLData>
...
<Type>2</Type>
...
</XMLData>
<XMLData>
...
<Type>3</Type>
...
</XMLData>
<AllMyData>
NOTE - all the independent elements that I am combining have the same tag name.
Thanks in advance for looking this up.
I have the following XML generated from various tables in my SQL
SERVER database
Depends on how you have it but if it is in a XML variable you can do like this.
declare #XML1 xml
declare #XML2 xml
declare #XML3 xml
set #XML1 = '<XMLData><Type>1</Type></XMLData>'
set #XML2 = '<XMLData><Type>2</Type></XMLData>'
set #XML3 = '<XMLData><Type>3</Type></XMLData>'
select #XML1, #XML2, #XML3
for xml path('AllMyData')
I can't comment but can answer so even though I think a comment is more appropriate, I'll expand on what rainabba answered above to add a bit more control. My .Net code needs to know the column name returned so I can't rely on auto-generated names but needed the very tip rainabba provided above otherwise.
This way, the xml can effectively be concatenated into a single row and the resulting column named. You could use this same approach to assign the results to an XML variable and return that from a PROC also.
SELECT (
SELECT XmlData as [*]
FROM
(
SELECT
xmlResult AS [*]
FROM
#XmlRes
WHERE
xmlResult IS NOT NULL
FOR XML PATH(''), TYPE
) as DATA(XmlData)
FOR XML PATH('')
) as [someColumnName]
If you use for xml type, you can combine the XML columns without casting them. For example:
select *
from (
select (
select 1 as Type
for xml path(''), type
)
union all
select (
select 2 as Type
for xml path(''), type
)
union all
select (
select 3 as Type
for xml path(''), type
)
) as Data(XmlData)
for xml path(''), root('AllMyData'), type
This prints:
<AllMyData>
<XmlData>
<Type>1</Type>
</XmlData>
<XmlData>
<Type>2</Type>
</XmlData>
<XmlData>
<Type>3</Type>
</XmlData>
</AllMyData>
As an addendum to Mikael Eriksson's answer - If you have a process where you need to continually add nodes and then want to group that under a single node, this is one way to do it:
declare #XML1 XML
declare #XML2 XML
declare #XML3 XML
declare #XMLSummary XML
set #XML1 = '<XMLData><Type>1</Type></XMLData>'
set #XMLSummary = (SELECT #XMLSummary, #XML1 FOR XML PATH(''))
set #XML2 = '<XMLData><Type>2</Type></XMLData>'
set #XMLSummary = (SELECT #XMLSummary, #XML2 FOR XML PATH(''))
set #XML3 = '<XMLData><Type>3</Type></XMLData>'
set #XMLSummary = (SELECT #XMLSummary, #XML3 FOR XML PATH(''))
SELECT #XMLSummary FOR XML PATH('AllMyData')
I needed to do the same but without knowing how many rows/variables were concerned and without extra schema added so here was my solution. Following this pattern, I can generate as many snippets as I want, combine them, pass them between PROCS or even return them from procs and at any point, wrap them up in containers all without modifying the data or being forced to add XML structure into my data. I use this approach with HTTP end points to provide XML Web services and with another trick that converts XML into JSON, to provide JSON WebServices.
-- SETUP A type (or use this design for a Table Variable) to temporarily store snippets into. The pattern can be repeated to pass/store snippets to build
-- larger elements and those can be further combined following the pattern.
CREATE TYPE [dbo].[XMLRes] AS TABLE(
[xmlResult] [xml] NULL
)
GO
-- Call the following as much as you like to build up all the elements you want included in the larger element
INSERT INTO #XMLRes ( xmlResult )
SELECT
(
SELECT
'foo' '#bar'
FOR XML
PATH('SomeTopLevelElement')
)
-- This is the key to "concatenating" many snippets into a larger element. At the end of this, add " ,ROOT('DocumentRoot') " to wrapp them up in another element even
-- The outer select is a time from user2503764 that controls the output column name
SELECT (
SELECT XmlData as [*]
FROM
(
SELECT
xmlResult AS [*]
FROM
#XmlRes
WHERE
xmlResult IS NOT NULL
FOR XML PATH(''), TYPE
) as DATA(XmlData)
FOR XML PATH('')
) as [someColumnName]
ALTER PROCEDURE usp_fillHDDT #Code int
AS
DECLARE #HD XML,#DT XML;
SET NOCOUNT ON;
select invhdcode, invInvoiceNO,invDate,invCusCode,InvAmount into #HD
from dbo.trnInvoiceHD where invhdcode=#Code
select invdtSlNo No,invdtitemcode ItemCode,invdtitemcode ItemName,
invDtRate Rate,invDtQty Qty,invDtAmount Amount ,'Kg' Unit into #DT from
dbo.trnInvoiceDt where invDtTrncode=#Code
set #HD = (select * from #HD HD FOR XML AUTO,ELEMENTS XSINIL);
set #DT = (select* from #DT DT FOR XML AUTO,ELEMENTS XSINIL);
SELECT CAST ('<OUTPUT>'+ CAST (ISNULL(#HD,'') AS VARCHAR(MAX))+ CAST ( ISNULL(#DT,'') AS VARCHAR(MAX))+ '</OUTPUT>' AS XML)
public String ReplaceSpecialChar(String inStr)
{
inStr = inStr.Replace("&", "&");
inStr = inStr.Replace("<", "<");
inStr = inStr.Replace(">", ">");
inStr = inStr.Replace("'", "'");
inStr = inStr.Replace("\"", """);
return inStr;
}

Resources