April 19, 2016 at 7:58 am
hi,
I have a table that contains one column that is has an xml
And it has come to my attention that maybe not all the xmls are the same. Meaning they have different nodes.
How can I check it without going one by one?
Thanks
Astrid
April 19, 2016 at 8:00 am
Astrid
Cast it as varchar, so that you can do comparisons. Please post some DDL and sample data if you need more detailed help than that.
John
April 19, 2016 at 8:10 am
Hi,
I have attached an excel with a sample of the data.
I don't know what you mean by converting to varchar, inside of each nod there are different values. so we are not comparing one string to the other.
I am just trying to understand if the nodes are the same.
thanks
April 19, 2016 at 8:23 am
This isn't something I've done myself before. Try the nodes method - it may give you what you're looking for.
John
April 19, 2016 at 8:26 am
astrid 69000 (4/19/2016)
Hi,I have attached an excel with a sample of the data.
I don't know what you mean by converting to varchar, inside of each nod there are different values. so we are not comparing one string to the other.
I am just trying to understand if the nodes are the same.
thanks
If you want someone to help you in detail, with working code, please provide sample DDL, data and expected results as per the link in my signature.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
April 19, 2016 at 9:04 am
So you want to compare the tree structure and not the values, correct?
I've used this dbo.XmlTable function to do it. Get the function from here:
http://beyondrelational.com/modules/2/blogs/28/posts/10495/xquery-lab-58-select-from-xml.aspx
And here is some simple code to get you started:
SET @cars =
'<?xml version="1.0" encoding="UTF-8"?>
<Cars>
<Car id="1234">
<Make>Volkswagen</Make>
<Model>Eurovan</Model>
<Year>2003</Year>
<Color>White</Color>
<Color>Blue</Color>
</Car>
<Car id="5678">
<Make>Honda</Make>
<Model>CRV</Model>
<Year>2009</Year>
<Color>Black</Color>
<Mileage>35,600</Mileage>
</Car>
</Cars>';
-- list all elements and attributes
SELECT xpath, value
FROM dbo.xmlTable(@cars)
WHERE value is not null
ORDER BY xpath
;
-- using nodes to get all rows
SELECT t.value('Make[1]','NVARCHAR(MAX)')+' '+ t.value('Model[1]','NVARCHAR(MAX)') AS CarType
from @cars.nodes('/Cars/Car') x(t)
April 19, 2016 at 10:27 am
thanks, but I don't understand what you are trying to do.
April 19, 2016 at 10:30 am
astrid 69000 (4/19/2016)
thanks, but I don't understand what you are trying to do.
Did you run the code provided?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
April 19, 2016 at 10:33 am
The code that Bill provided yes? and it it didn't work.
I am reading the link he provided
and trying to work with that.
April 19, 2016 at 10:59 am
astrid 69000 (4/19/2016)
The code that Bill provided yes? and it it didn't work.I am reading the link he provided
and trying to work with that.
Saying that something "doesn't work" in the world of IT development really isn't helpful.
The link he provided gives a function which his example invokes.
He was suggesting that you take a look at that function too.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
April 20, 2016 at 10:36 am
Thanks so much.
I read and read and I understood. and it worked :-P:-P
Here is my code
declare @x xml
DECLARE @site_value INT;
SET @site_value = 0;
WHILE @site_value <= 1000
BEGIN
select @x = (select myxml from myxl where id = @site_value)
SET @site_value = @site_value + 1;
insert into mytablexml
SELECT FullPath FROM dbo.XMLTable(@x);
end;
April 20, 2016 at 10:56 am
astrid 69000 (4/20/2016)
Thanks so much.I read and read and I understood. and it worked :-P:-P
Here is my code
declare @x xml
DECLARE @site_value INT;
SET @site_value = 0;
WHILE @site_value <= 1000
BEGIN
select @x = (select myxml from myxl where id = @site_value)
SET @site_value = @site_value + 1;
insert into mytablexml
SELECT FullPath FROM dbo.XMLTable(@x);
end;
Excellent, well done.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply