3 Replies Latest reply: Dec 20, 2012 4:18 AM by TPD-Opitz RSS

    how to create tagging attributes

    TPD-Opitz
      Hello,

      this are two questions in one...

      1. how do I create "empty" attributes like this: <tt>&lt;Element Attribute></tt>?

      2. How do I trigger the creation of the attribute by a value from DB?
      SQL> WITH my_data AS
        2         (SELECT 'test1' AS element_name
        3               , 0 AS tag_attrib
        4            FROM DUAL
        5          UNION ALL
        6          SELECT 'test2' AS element_name
        7               , 1 AS tag_attrib
        8            FROM DUAL)
        9  SELECT XMLELEMENT( element_name )
       10       , XMLELEMENT( element_name
       11                   , case when tag_attrib = 1 then xmlattributes( 1 as "tag_attrib" ) else null end
       12                    )
       13    FROM my_data;
                       , case when tag_attrib = 1 then xmlattributes( 1 as "tag_attrib" ) else null end
                                                                        *
      FEHLER in Zeile 11:
      ORA-00907: missing right parenthesis
      
      SQL>
        • 1. Re: how to create tagging attributes
          odie_63
          1. how do I create "empty" attributes like this: <tt>&lt;Element Attribute></tt>?
          That's not valid.
          Did you mean :
          <Elem Attr="">
          ?

          2. How do I trigger the creation of the attribute by a value from DB?
          By moving the CASE statement into XMLAttributes.
          XMLAttributes doesn't generate attribute for NULL values :
          SQL> WITH my_data(element_name, tag_attrib) AS (
            2    SELECT 'test1', 0 FROM DUAL UNION ALL
            3    SELECT 'test2', 1 FROM DUAL
            4  )
            5  SELECT XMLSerialize(content
            6           XMLElement( element_name
            7           , XMLAttributes(
            8               case when tag_attrib = 1
            9                    then tag_attrib
           10               end as "tag_attrib"
           11             )
           12           )
           13           as varchar2(2000)
           14           indent
           15         )
           16  FROM my_data;
           
          XMLSERIALIZE(CONTENTXMLELEMENT
          --------------------------------------------------------------------------------
          <ELEMENT_NAME/>
          <ELEMENT_NAME tag_attrib="1"/>
           
          • 2. Re: how to create tagging attributes
            TPD-Opitz
            odie_63 wrote:
            1. how do I create "empty" attributes like this: <tt>&lt;Element Attribute></tt>?
            That's not valid.
            Did you mean :
            <Elem Attr="">
            ?
            No.

            bye
            TPD
            • 3. Re: how to create tagging attributes
              odie_63
              odie_63 wrote:
              1. how do I create "empty" attributes like this: <tt>&lt;Element Attribute></tt>?
              That's not valid.
              Did you mean :
              <Elem Attr="">
              ?
              No.
              Then you cannot. What you want is not XML.