473,408 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

FOR XML EXPLICIT can't get element 4 going

Hello all,

I'm trying to generate some XML directly from MS SQL with the
following code

SELECT 1 AS tag
, NULL AS parent
, NULL AS [GoogleCustomizations!1]
, NULL AS [Annotations!2]
, NULL AS [Annotation!3]
, NULL AS [Annotation!3!about]
, NULL AS [Annotation!3!score]
, NULL AS [Label!4]
, NULL AS [Label!4!name]
UNION
SELECT 2 AS tag
, 1 AS parent
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
UNION
SELECT TOP 50 3 AS tag
, 2 AS parent
, NULL
, NULL
, NULL
, 'www.' + domainName
, 1 -- score
, NULL
, NULL
FROM tbl_auDomainName
UNION
SELECT 4 AS tag
, 3 AS parent
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, '_cse_ad-o6lgdody'
FOR XML EXPLICIT

The XML it needs to create is as following

<GoogleCustomizations>
<Annotations>
<Annotation about="www.clickfind.com.au/*" score="1">
<Label name="_cse_ad-o6lgdody" />
</Annotation>
<Annotation about="www.lookle.com/*" score="1">
<Label name="_cse_ad-o6lgdody" />
</Annotation>
<Annotation about="www.sensis.com.au/*" score="1">
<Label name="_cse_ad-o6lgdody" />
</Annotation>
</Annotations>
</GoogleCustomizations>

It is currently creating

<GoogleCustomizations>
<Annotations>
<Annotation about="www.10000steps.org.au" score="1" />
<Annotation about="www.101fm.asn.au" score="1" />
<Annotation about="www.aao.gov.au" score="1">
<Label name="_cse_ad-o6lgdody" />
</Annotation>
</Annotations>
</GoogleCustomizations>

I cannot get my head around how I can get the label <Label
name="_cse_ad-o6lgdody" />
in each element. Does anyone know?

Thanks in advance.
Jan 7 '08 #1
2 1425
Pacific Fox (ta*******@gmail.com) writes:
The XML it needs to create is as following

<GoogleCustomizations>
<Annotations>
<Annotation about="www.clickfind.com.au/*" score="1">
<Label name="_cse_ad-o6lgdody" />
</Annotation>
<Annotation about="www.lookle.com/*" score="1">
<Label name="_cse_ad-o6lgdody" />
</Annotation>
<Annotation about="www.sensis.com.au/*" score="1">
<Label name="_cse_ad-o6lgdody" />
</Annotation>
</Annotations>
</GoogleCustomizations>

It is currently creating

<GoogleCustomizations>
<Annotations>
<Annotation about="www.10000steps.org.au" score="1" />
<Annotation about="www.101fm.asn.au" score="1" />
<Annotation about="www.aao.gov.au" score="1">
<Label name="_cse_ad-o6lgdody" />
</Annotation>
</Annotations>
</GoogleCustomizations>

I cannot get my head around how I can get the label <Label
name="_cse_ad-o6lgdody" />
in each element. Does anyone know?
This seems to do what you want:

SELECT 1 AS tag
, NULL AS parent
, NULL AS [GoogleCustomizations!1]
, NULL AS [Annotations!2]
, NULL AS [Annotation!3]
, NULL AS [Annotation!3!about]
, NULL AS [Annotation!3!score]
, NULL AS [Annotation!3!Label!element]
UNION
SELECT 2 AS tag
, 1 AS parent
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
UNION
SELECT 3 AS tag
, 2 AS parent
, NULL
, NULL
, EmployeeID
, FirstName
, 1 -- score
, '_cse_ad-o6lgdody'
FROM Employees
FOR XML EXPLICIT

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 7 '08 #2
Hi, thanks for replying.

Unfortunately it creates the right structure, except for it not
creating the name="" attribute. It creates the following (only showing
Annotation elements)

<Annotation about="www.10000steps.org.au" score="1">
<Label>_cse_ad-o6lgdody</Label>
</Annotation>
<Annotation about="www.101fm.asn.au" score="1">
<Label>_cse_ad-o6lgdody</Label>
</Annotation>
<Annotation about="www.121money.com.au" score="1">
<Label>_cse_ad-o6lgdody</Label>
</Annotation>
<Annotation about="www.1300rubbish.com.au" score="1">
<Label>_cse_ad-o6lgdody</Label>
</Annotation>

While it should be

<Annotation about="www.10000steps.org.au" score="1">
<Label name="_cse_ad-o6lgdody"/>
</Annotation>

Thanks in advance.
Jan 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Michael B. Allen | last post by:
Coming from C and Java on *nix I'm a little out of my element messing around with CList and MSVC++ but I think my issues are largely syntactic. I have an ADT that I use called a 'varray' that can...
2
by: Dave Theese | last post by:
Hello again, In the program below, the following line is of interest: bar.insert(make_pair(42, 17)); insert() expects a pair<foo<1>, foo<2> >. I'm giving it a pair <int, int>. But this is...
4
by: CoolPint | last post by:
I would be grateful if someone could point out if I am understanding correctly and suggest ways to improve. Sorry for the long message and I hope you will kindly bear with it. I have to make it...
9
by: Tanmoy Bhattacharya | last post by:
Hi, This is a question about whether I am right that a particular syntactic sugar is missing in C++. Let me explain with an example. Let us say I have a class for complex numbers, and I want...
0
by: Chi | last post by:
This is a problem that has been nagging me for a while, and I cannot figure out how to best solve the problem: I have a stored procedure that returns multi-level "nested" XML and inline XDR. My...
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
24
by: Peter Maas | last post by:
The Python FAQ 1.4.5 gives 3 reasons for explicit self (condensed version): 1. Instance variables can be easily distinguished from local variables. 2. A method from a particular class can be...
14
by: Noone | last post by:
Hello all, Ok, I want to create a program that will load plugins (dll's) from a plugin folder. I can create the forms and put them into a dll but I cannot actually add them dynamically at run...
1
pbmods
by: pbmods | last post by:
Today marks the 85% mark of about a week of trying to learn SOAP, while the client is furious and demanding to know when his site will be done. I finally figured out why the server kept throwing...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.