2

I am trying for a query which returns and XML output which has one of the attribute value as XML without <, /> encoded.

Example:

<Event EventLogId="124018" EventCategoryCode="ABC" 
       EventTypeCode="ERROR" 
       xmlObject="<attributes><attribute>A1</attribute></attributes>" />

<Event EventLogId="124019" EventCategoryCode="DEF" 
       EventTypeCode="Warning" 
       xmlObject="<attributes><attribute>A2</attribute></attributes>" />

I tried this query

SELECT  
    EventLogId  AS EventLogId 
    ,EventCategoryCode AS EventCategoryCode        
    ,EventTypeCode AS EventTypeCode      
    ,CAST(Event.xmlObject AS NVARCHAR(MAX)) as xmlObject
FROM 
    EventLog Event (NOLOCK) 
FOR XML AUTO

But I am getting this output

<Event EventLogId="124018" EventCategoryCode="ABC" 
       EventTypeCode="ERROR" 
       xmlObject="&lt;attributes&gt;&lt;attribute&gt;A1&lt;/attribute&gt;&lt;/attributes&gt;" />

<Event EventLogId="124019" EventCategoryCode="DEF" 
       EventTypeCode="Warning" 
       xmlObject="&lt;attributes&gt;&lt;attribute&gt;A2&lt;/attribute&lt;&lt;/attributes&gt;" />

I want <, /> in place of &lt; and &gt;

2
  • 2
    can't do that-- not legal XML. Commented Sep 10, 2015 at 13:36
  • And any XML reader should be able to translate/de-entitize it back for you. Commented Sep 10, 2015 at 14:39

1 Answer 1

2

It is not valid to have non-escaped (i.e. not entity encoded) characters in attributes or anywhere in XML.

To be 100% accurate, before I get lots of comments, you can use the special DATA syntax, but that is not legal in an attribute. Also it is rare to see this feature used.

You can read the standard here (http://www.w3.org/TR/xml/) The base XML standard is actually quite short and should take you less than an hour to read.

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.