XQuery Error when reading attribute from parentnode with *typed* XML (value() requires a singleton)Read xsi:type from T-SQLjaxb element with complexContent, restriction and attributeget XML-Schema Restrictions with XPathHow to query for Xml values and attributes from table in SQL Server?SQL sql:variable usage in XML insertwork around for validating XML child elementsread line and keep spaces from xml fileSQL query with XML parameterHow do I extract data from xml using xml value() and openxml method?How does an XML Validator know where to find the schema instance declared in an xml document in order to parse and use the xsd?
Why are Gatwick's runways too close together?
How to create events observer that only call when REST api dispatch events?
What should I call bands of armed men in the Middle Ages?
TEMPO: play a (mp3) sound in animated GIF/PDF/SVG
What ability do tools use?
Normalization constant of a planar wave
Voltage across a resistor
Is there a standardised way to check fake news?
What does the phrase "pull off sick wheelies and flips" mean here?
Email address etiquette - Which address should I use to contact professors?
Is it legal for a company to enter an agreement not to hire employees from another company?
Are differences between uniformly distributed numbers uniformly distributed?
Why did I get only 5 points even though I won?
How to divide item stack in MC PE?
How to describe accents?
0xF1 opcode-prefix on i80286
WhatsApp calls on an iPhone and "data" and "minutes"
How can God warn people of the upcoming rapture without disrupting society?
Is this n-speak?
If "more guns less crime", how do gun advocates explain that the EU has less crime than the US?
How to remove ambiguity: "... lives in the city of H, the capital of the province of NS, WHERE the unemployment rate is ..."?
Heating Margarine in Pan = loss of calories?
Is the equation dG = Vdp − SdT valid only for a reversible process? Can it be applied for an irreversible one too?
Do beef farmed pastures net remove carbon emissions?
XQuery Error when reading attribute from parentnode with *typed* XML (value() requires a singleton)
Read xsi:type from T-SQLjaxb element with complexContent, restriction and attributeget XML-Schema Restrictions with XPathHow to query for Xml values and attributes from table in SQL Server?SQL sql:variable usage in XML insertwork around for validating XML child elementsread line and keep spaces from xml fileSQL query with XML parameterHow do I extract data from xml using xml value() and openxml method?How does an XML Validator know where to find the schema instance declared in an xml document in order to parse and use the xsd?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a simple XML:
DECLARE @x1 xml = '<r>
<o a="1">
<o a="2">
</o>
</o>
</r>';
And select the following:
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x1.nodes('/r//o') r(o);
Everything is nice:
NULL
1
When I use typed XML:
CREATE XML SCHEMA COLLECTION [dbo].test AS '
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="r">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="o" type="o" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="o">
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="o" type="o" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="a" type="xsd:string" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>'
GO
DECLARE @x2 xml(dbo.test) = '<r>
<o a="1">
<o a="2">
</o>
</o>
</r>';
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
I got the Error:
XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'
Why does the untyped XML works and the typed XML not?
sql
add a comment |
I have a simple XML:
DECLARE @x1 xml = '<r>
<o a="1">
<o a="2">
</o>
</o>
</r>';
And select the following:
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x1.nodes('/r//o') r(o);
Everything is nice:
NULL
1
When I use typed XML:
CREATE XML SCHEMA COLLECTION [dbo].test AS '
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="r">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="o" type="o" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="o">
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="o" type="o" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="a" type="xsd:string" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>'
GO
DECLARE @x2 xml(dbo.test) = '<r>
<o a="1">
<o a="2">
</o>
</o>
</r>';
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
I got the Error:
XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'
Why does the untyped XML works and the typed XML not?
sql
StackOverflow has always objected to things like short questions and short answers, requiring you to pad them with rubbish in order to satisfy its rules checker. Looks like it's getting worse. Just keep pumping out the padding and hope they'll improve the rules.
– Michael Kay
Mar 27 at 9:03
add a comment |
I have a simple XML:
DECLARE @x1 xml = '<r>
<o a="1">
<o a="2">
</o>
</o>
</r>';
And select the following:
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x1.nodes('/r//o') r(o);
Everything is nice:
NULL
1
When I use typed XML:
CREATE XML SCHEMA COLLECTION [dbo].test AS '
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="r">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="o" type="o" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="o">
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="o" type="o" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="a" type="xsd:string" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>'
GO
DECLARE @x2 xml(dbo.test) = '<r>
<o a="1">
<o a="2">
</o>
</o>
</r>';
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
I got the Error:
XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'
Why does the untyped XML works and the typed XML not?
sql
I have a simple XML:
DECLARE @x1 xml = '<r>
<o a="1">
<o a="2">
</o>
</o>
</r>';
And select the following:
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x1.nodes('/r//o') r(o);
Everything is nice:
NULL
1
When I use typed XML:
CREATE XML SCHEMA COLLECTION [dbo].test AS '
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="r">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="o" type="o" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="o">
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence>
<xsd:element name="o" type="o" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="a" type="xsd:string" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>'
GO
DECLARE @x2 xml(dbo.test) = '<r>
<o a="1">
<o a="2">
</o>
</o>
</r>';
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
I got the Error:
XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'
Why does the untyped XML works and the typed XML not?
sql
sql
edited Mar 27 at 9:02
Dale Burrell
4,4245 gold badges27 silver badges57 bronze badges
4,4245 gold badges27 silver badges57 bronze badges
asked Mar 27 at 8:45
K. EdelbertK. Edelbert
84 bronze badges
84 bronze badges
StackOverflow has always objected to things like short questions and short answers, requiring you to pad them with rubbish in order to satisfy its rules checker. Looks like it's getting worse. Just keep pumping out the padding and hope they'll improve the rules.
– Michael Kay
Mar 27 at 9:03
add a comment |
StackOverflow has always objected to things like short questions and short answers, requiring you to pad them with rubbish in order to satisfy its rules checker. Looks like it's getting worse. Just keep pumping out the padding and hope they'll improve the rules.
– Michael Kay
Mar 27 at 9:03
StackOverflow has always objected to things like short questions and short answers, requiring you to pad them with rubbish in order to satisfy its rules checker. Looks like it's getting worse. Just keep pumping out the padding and hope they'll improve the rules.
– Michael Kay
Mar 27 at 9:03
StackOverflow has always objected to things like short questions and short answers, requiring you to pad them with rubbish in order to satisfy its rules checker. Looks like it's getting worse. Just keep pumping out the padding and hope they'll improve the rules.
– Michael Kay
Mar 27 at 9:03
add a comment |
1 Answer
1
active
oldest
votes
It looks as though you well understand that this is not the usual problem of having to convince the parser that there is only one thing being passed into value(). This problem is specific to typed XML, as you have observed.
Using google I found this ancient blogpost with the promising text
rt is part of the XQuery 1.0/XPath 2.0 data model.
Most people get by that. The real fun starts when you do examples using untyped XML and XPath expressions with the text() node test. text() works just fine when using untyped XML, but fails against typed XML with simple content
It talks about the SQL Books Online and the SQL Server 2005 XML Best Practices paper, which I think is this book here. I haven't looked for a more up-to-date reference. But using what I found there I have been able to fix your problem: Simple replace
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
with
SELECT r.o.value('fn:string(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
Basically, value() doesn't like being given values of a typed-xml-type, but wants strings. So we give it a string.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55372974%2fxquery-error-when-reading-attribute-from-parentnode-with-typed-xml-value-re%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It looks as though you well understand that this is not the usual problem of having to convince the parser that there is only one thing being passed into value(). This problem is specific to typed XML, as you have observed.
Using google I found this ancient blogpost with the promising text
rt is part of the XQuery 1.0/XPath 2.0 data model.
Most people get by that. The real fun starts when you do examples using untyped XML and XPath expressions with the text() node test. text() works just fine when using untyped XML, but fails against typed XML with simple content
It talks about the SQL Books Online and the SQL Server 2005 XML Best Practices paper, which I think is this book here. I haven't looked for a more up-to-date reference. But using what I found there I have been able to fix your problem: Simple replace
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
with
SELECT r.o.value('fn:string(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
Basically, value() doesn't like being given values of a typed-xml-type, but wants strings. So we give it a string.
add a comment |
It looks as though you well understand that this is not the usual problem of having to convince the parser that there is only one thing being passed into value(). This problem is specific to typed XML, as you have observed.
Using google I found this ancient blogpost with the promising text
rt is part of the XQuery 1.0/XPath 2.0 data model.
Most people get by that. The real fun starts when you do examples using untyped XML and XPath expressions with the text() node test. text() works just fine when using untyped XML, but fails against typed XML with simple content
It talks about the SQL Books Online and the SQL Server 2005 XML Best Practices paper, which I think is this book here. I haven't looked for a more up-to-date reference. But using what I found there I have been able to fix your problem: Simple replace
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
with
SELECT r.o.value('fn:string(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
Basically, value() doesn't like being given values of a typed-xml-type, but wants strings. So we give it a string.
add a comment |
It looks as though you well understand that this is not the usual problem of having to convince the parser that there is only one thing being passed into value(). This problem is specific to typed XML, as you have observed.
Using google I found this ancient blogpost with the promising text
rt is part of the XQuery 1.0/XPath 2.0 data model.
Most people get by that. The real fun starts when you do examples using untyped XML and XPath expressions with the text() node test. text() works just fine when using untyped XML, but fails against typed XML with simple content
It talks about the SQL Books Online and the SQL Server 2005 XML Best Practices paper, which I think is this book here. I haven't looked for a more up-to-date reference. But using what I found there I have been able to fix your problem: Simple replace
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
with
SELECT r.o.value('fn:string(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
Basically, value() doesn't like being given values of a typed-xml-type, but wants strings. So we give it a string.
It looks as though you well understand that this is not the usual problem of having to convince the parser that there is only one thing being passed into value(). This problem is specific to typed XML, as you have observed.
Using google I found this ancient blogpost with the promising text
rt is part of the XQuery 1.0/XPath 2.0 data model.
Most people get by that. The real fun starts when you do examples using untyped XML and XPath expressions with the text() node test. text() works just fine when using untyped XML, but fails against typed XML with simple content
It talks about the SQL Books Online and the SQL Server 2005 XML Best Practices paper, which I think is this book here. I haven't looked for a more up-to-date reference. But using what I found there I have been able to fix your problem: Simple replace
SELECT r.o.value('(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
with
SELECT r.o.value('fn:string(../@a)[1]','varchar(20)') FROM @x2.nodes('/r//o') r(o);
Basically, value() doesn't like being given values of a typed-xml-type, but wants strings. So we give it a string.
answered Mar 27 at 9:13
AakashMAakashM
54.1k13 gold badges130 silver badges173 bronze badges
54.1k13 gold badges130 silver badges173 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55372974%2fxquery-error-when-reading-attribute-from-parentnode-with-typed-xml-value-re%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
StackOverflow has always objected to things like short questions and short answers, requiring you to pad them with rubbish in order to satisfy its rules checker. Looks like it's getting worse. Just keep pumping out the padding and hope they'll improve the rules.
– Michael Kay
Mar 27 at 9:03