0

We are trying to get IdValue from sql query. We are using sql server 2005.

DECLARE @MyXML XML
SET @MyXML = '<Candidate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ns.hr-xml.org/2007-04-15">
  <CandidateProfile>
    <ProfileId>
      <IdValue>9499063</IdValue>
    </ProfileId>
  </CandidateProfile>
  </Candidate>'

SELECT @MyXML.value('Candidate[1]/CandidateProfile[1]/ProfileId[1]','varchar(10)') AS Id

This is not working because of the name space in the Candidate tag.

Please let me know how to xquery with the namespace.

1 Answer 1

4
    SELECT @MyXML.value(
    'declare namespace hr="http://ns.hr-xml.org/2007-04-15";
    hr:Candidate[1]/hr:CandidateProfile[1]/hr:ProfileId[1]','varchar(10)'
    ) 
    AS Id 

http://msdn.microsoft.com/en-US/library/ms189075(v=SQL.90).aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.