This Question is Assumed Answered

1 "correct" answer available (5 pts) 15 "helpful" answers available (3 pts)
4 Replies Last post: Jun 2, 2008 12:38 AM by varshuj

Creating RecordSet using XMLElaboration

May 28, 2008 11:56 PM

Click to view varshuj's profile Level 2 varshuj 36 posts since
Mar 6, 2008

Hi,

Using XmlElaboration i am creating recordset .

Passing RecordFields and XmlKeywordPrototype to XmlElaboration.

My XML file is having some only closing tag and not corresponding value , like

<item>

<title> ABC <title/>

<exists/>

<item/>

indicating that a column should have value = true if tag is present.

And if tag is not there then column should get value = false.


How can i do this, whether i can put some condition while creating RecordSet in XMLElaboration or

search for that element tag and pass boolean value to RecordSet for a particular RecordData.


Thanks

varsha

Click to view dmccrae's profile Curl dmccrae 18 posts since
Oct 10, 2007
1. Re: Creating RecordSet using XMLElaboration May 29, 2008 12:10 PM
Varsha --

I'm happy to see you're using XDM and XDM elaboration!

Here are a couple possible approaches for the issue you describe. The first, using alternate domains, is somewhat specialized, but is worth knowing about. The second, using xpath expressions, is much more general. I often start with the xpath approach.

Hope this helps.

    • Doug

I'm assuming you started with a test case something like this, and found that the "keyword elaboration" of the empty 'exists' tag was an empty string which was rejected by the parser for the boolean domain in your recordset.

{def test = "
<items>
 <item>
  <title>ABC</title>
  <exists/>
 </item>
 <item>
  <title>XYZ</title>
 </item>
</items>"
}
{def xml =
    {build-xml preserve-whitespace? = false, test}.root
}    
{value
    || define the transformation
    def e =
        {xml-elaboration
            {"items" {...:RecordData}:RecordSet
                {RecordSet
                    || explicit structure, not declared in source
                    {RecordFields
                        {RecordField "title", domain = String},
                        {RecordField "exists", domain = bool}},
                    || records corresponding to items
                    {splice ...}}}
            || contents will be treated as keywords
            {"item" RecordData}
            || treat these tags as keywords
            {"title" XmlKeywordPrototype}
            {"exists" XmlKeywordPrototype}
            || other tags will be ignored
        }
   
   || transform the source
   def rs = {e.elaborate xml} asa RecordSet
   
   || display the data
   {RecordGrid record-source = rs, 
       width = 10cm, height = 4cm,
       {RecordGridColumn "title"},
       {RecordGridColumn "exists"}}
}


That specific issue could be addressed by using a specialized domain that parses any string as true, so the presence or absence of the tag would control the value. Then, using 'domain = {SpecialBoolDomain }' instead of 'domain = bool' would give the result you want.


{define-class public SpecialBoolDomain {inherits StandardBoolDomain}
  {constructor public {default ...}
    {construct-super {splice ...}}
  }
  {method public {parse x:String}:any
    {return true}
  }
}


But that approach is specialized, and couples the recordset field descriptors with the data exchange format. A more general approach is to use xpath expressions to obtain appropriate values from each element. When the argument pattern in an 'elaborate-xml' clause has an XDMElement type, that object is available to compute the result. The the elaboration could be defined like this.

    || define the transformation
    def e =
        {xml-elaboration
            {"items" {...:RecordData}:RecordSet
                {RecordSet
                    || explicit structure, not declared in source
                    {RecordFields
                        {RecordField "title", domain = String},
                        {RecordField "exists", domain = bool}},
                    || records corresponding to items
                    {splice ...}}}
            || process contents using xpath
            {"item" {x:XDMElement}:RecordData
                def title = {x.search "title"}.as-String
                def exists = {x.search "exists"}.as-bool
                {RecordData
                    title = title,
                    exists = exists}}
        }


By the way, you can use xpath expressions with any XDM object, regardless of whether you're using elaborate-xml.

Click to view varshuj's profile Level 2 varshuj 36 posts since
Mar 6, 2008
2. Re: Creating RecordSet using XMLElaboration May 30, 2008 7:10 AM
in response to: dmccrae

Thanks a lot dmccrae for your help.

It worked but having one problem.

I couldnt get value of exists column in recordgrid.

but i could set another column's value on condition

if exists column value == true then set X column value = true and

this X column's value as "true " i get in RecordGrid.

Click to view dmccrae's profile Curl dmccrae 18 posts since
Oct 10, 2007
3. Re: Creating RecordSet using XMLElaboration May 30, 2008 3:15 PM
in response to: varshuj
I do not understand the problem.

Are you using the domain approach or the xpath approach?

If you can send the code you're using, it would help me understand whats happening.
Click to view varshuj's profile Level 2 varshuj 36 posts since
Mar 6, 2008
4. Re: Creating RecordSet using XMLElaboration Jun 2, 2008 12:38 AM
in response to: dmccrae

Oh!! i got it. Actually when i set exist column as String and pass some value if {x.search "exist"}.as-bool == true

Thanks dmccrae for your help.