Topic
6 replies Latest Post - ‏2014-01-09T08:08:08Z by MatthiasNicola
XpertDBA
XpertDBA
3 Posts
ACCEPTED ANSWER

Pinned topic Updating attributes

‏2014-01-07T21:03:50Z |

Hello,  I'm a DB2 PureXML newbie, so sorry if this question is easy or obvious.

 

If I have repeating pieces of XML like the following that have different appender elements, and I want to change an attribute inside a particular block based upon the value of another attribute (for example the appender name), what would be an example of an UPDATE statement I could write for this case.  For example if I want to change the value to FALSE for one of the Param name attributes with the Appender name one (i.e. APPENDER NAME = LambLogServer, and Param name = APPEND).

- <appender name="LambLogServer"class="org.apache.log4j.DailyRollingFileAppender">
  <param name="DatePattern"value="'.'yyyy-MM-dd" />
  <param name="File"value="${user.install.root}/logs/app/pubsub.log" />
  <param name="Append"value="true" />
- <layout class="com.g2switch.common.logger.G2PatternLayout">
  <param name="ConversionPattern"value="%D|%T|%z|%l|%p|%I|%c|%N|%t|%m|%E%n" />
  </layout>
  </appender>
- <appender name="DataTrackingHandOffLogServer"class="org.apache.log4j.DailyRollingFileAppender">
  <param name="DatePattern"value="'.'yyyy-MM-dd" />
  <param name="File"value="${user.install.root}/logs/app/dataTrackingHandoff.log" />
  <param name="Append"value="true" />
- <layout class="com.g2switch.common.logger.G2PatternLayout">
  <param name="ConversionPattern"value="%D|%T|%z|%l|%p|%I|%c|%N|%t|%m|%E%n" />
  </layout>
  </appender>

 

  • MatthiasNicola
    MatthiasNicola
    309 Posts
    ACCEPTED ANSWER

    Re: Updating attributes

    ‏2014-01-08T16:20:39Z  in response to XpertDBA

    Hello,

    you might find the following article useful, which explains different ways of writing XML updates in DB2.

    http://www.ibm.com/developerworks/data/library/techarticle/dm-0710nicola/

    Specifically you should look at the section "Modify repeating nodes", which shows you how to modify one occurrence of an element that occurs multiple times, such as the "param" element in your example.  Take a look at example "Update 20", which is similar to what you need here,

    Give it try and let us know here if you need additional help.

    Matthias

     

     

     

  • MatthiasNicola
    MatthiasNicola
    309 Posts
    ACCEPTED ANSWER

    Re: Updating attributes --> name/value pairs

    ‏2014-01-08T16:30:56Z  in response to XpertDBA

    Independent from the specific update question that you asked, I would like to comment the design of the XML format in your example. The element name "param" is a very generic and non-descriptive name, and the actual name of the parameter is stored in a separate attribute "name":

     

    <param name="DatePattern" value="'.'yyyy-MM-dd" />

    <param name="File" value="${user.install.root}/logs/app/dataTrackingHandoff.log" />

      <param name="Append" value="true" />

     

    In my experience it usually better to use the actual names as the element names, like this:

     

    <DatePattern   value="'.'yyyy-MM-dd" />

    <File value="${user.install.root}/logs/app/dataTrackingHandoff.log" />

      <Append value="true" />

    With this design it is easier to index and to query specific elements. The queries will be less complicated and the query performance can be much better. I have seen numerous real XML applications where using actual field names as element names (rather than generic names) has provided significant gains in performance and simplicity.

    The background to this is explained in the following blog post, if you are interested:

     

    http://nativexmldatabase.com/2011/01/21/namevalue-pairs-a-pretty-bad-idea-in-xml-as-in-relational/

     

    Matthias

     

    • XpertDBA
      XpertDBA
      3 Posts
      ACCEPTED ANSWER

      Re: Updating attributes --> name/value pairs

      ‏2014-01-08T17:41:50Z  in response to MatthiasNicola

      That's all well and good, but these are IBM WAS configuration files that are standardized in this format, and I have no control over how they are put together.  If I had my choice, I would do it like you're saying, but it's not my design, but IBMs.

      • MatthiasNicola
        MatthiasNicola
        309 Posts
        ACCEPTED ANSWER

        Re: Updating attributes --> name/value pairs

        ‏2014-01-08T19:26:12Z  in response to XpertDBA

        Fair enough.

        Hope you're successful with the XML updates. Let me know if you have additional questions on this.

  • XpertDBA
    XpertDBA
    3 Posts
    ACCEPTED ANSWER

    Re: Updating attributes

    ‏2014-01-08T19:36:38Z  in response to XpertDBA

    Just for future reference, I found out how to do what I was looking for......(updating one attribute within other elements/attributes, for example:

     

    update uref.CONFIG_FILES

    set CONTENT_XML = xmlquery( 'transform

    copy $new := $CONTENT_XML

    modify do replace value of $new/*:configuration/category[@name="RequestResponseLogServer"]/priority[@value="DEBUG"]/@value with "INFO"

    return  $new') WHERE

    FILE_NM='logconfig' and scope='dev' and  server='_root'

    • MatthiasNicola
      MatthiasNicola
      309 Posts
      ACCEPTED ANSWER

      Re: Updating attributes

      ‏2014-01-09T08:08:08Z  in response to XpertDBA

      Very nice!

      Thanks for sharing the solution with the wider audience in this forum.