2

Needed some help to parse text in Paragraph element in following XML in SQL server.

<FlowDocument PagePadding="5,5,5,5" Name="RTDocument" AllowDrop="True" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">   
  <Paragraph>Licence Number: 04467</Paragraph>
  <Paragraph>Licence Number: 3535333</Paragraph>
</FlowDocument>

Please share any queries you may have.

Thank you

3
  • below is the XML <FlowDocument PagePadding="5,5,5,5" Name="RTDocument" AllowDrop="True" xmlns="schemas.microsoft.com/winfx/2006/xaml/presentation"> <Paragraph>Licence Number: 04467</Paragraph><Paragraph>Licence Number: dddd</Paragraph></FlowDocument> Commented Mar 2, 2016 at 18:07
  • 2
    Please put the XML in your question, not in the comments. Also: stackoverflow.com/help/how-to-ask Commented Mar 2, 2016 at 18:10
  • Hi @SidharthSoneja if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. Commented Apr 21, 2016 at 18:14

2 Answers 2

3

One way of doing this is: (If they have the same namespace)

;with xmlnamespaces(default 'schemas.microsoft.com/winfx/2006/xaml/presentation')
select @xml.value('(/FlowDocument/Paragraph)[1]', 'varchar(max)') + ' ' + 
    @xml.value('(/FlowDocument/Paragraph)[2]', 'varchar(max)')

Another way:

select data.col.value('(*:Paragraph)[1]','varchar(100)') 
    + ' ' +  data.col.value('(*:Paragraph)[2]','varchar(100)') as ParamName
FROM @xml.nodes('(*:FlowDocument)') as data(col) 
Sign up to request clarification or add additional context in comments.

Comments

3

Or (complementing Roberto answer)

;WITH XMLNAMESPACES(DEFAULT 'schemas.microsoft.com/winfx/2006/xaml/presentation')

SELECT  FlowDocument.Paragraph.value('.', 'varchar(MAX)')
FROM    @xml.nodes('//FlowDocument/Paragraph') AS FlowDocument(Paragraph)

If has many Paragraph tags

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.