XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
david mareSubject: removing unwanted attributes resulting from database conversion to xml
Author: david mare
Date: 20 Feb 2008 08:38 PM
Hi,

I have an XQuery which reads data from a FOXPRO data source. The XQuery is returning some data type attributes in the first occurrence or a row of the output XML. Can I configure my XQuery scenario so it doesn't insert this information? Here's my XQuery:

declare variable $table1 := doc("converter:dBase_V?file:///D:/Data/test.DBF")/table/row;

<dataroot>
{
for $row1 in $table1
return
<MYTABLE>
{ $row1/FIELD1 }
{ $row1/FIELD2 }
{ $row1/FIELD3 }
</MYTABLE>
}
</dataroot>

Here's the resulting XML file:

<dataroot>
<MYTABLE>
<FIELD1 type="C" length="4">content in field1</FIELD1>
<FIELD2 type="D" length="8">content in field2</FIELD2>
<FIELD3 type="C" length="10">content in field3</FIELD3>
</MYTABLE>
<MYTABLE>
<FIELD1>content in field1</FIELD1>
<FIELD2>content in field2</FIELD2>
<FIELD3>content in field3</FIELD3>
</MYTABLE>
<MYTABLE>
<FIELD1>content in field1</FIELD1>
<FIELD2>content in field2</FIELD2>
<FIELD3>content in field3</FIELD3>
</MYTABLE>
</dataroot>

I know I could do a second pass and strip those attributes, but I'd like to avoid that.

thanks

Postnext
Minollo I.Subject: removing unwanted attributes resulting from database conversion to xml
Author: Minollo I.
Date: 20 Feb 2008 09:20 PM
How about:
<dataroot>
{
for $row1 in $table1
return
<MYTABLE>
<FIELD1>{ $row1/FIELD1/text() }</FIELD1>
<FIELD2>{ $row1/FIELD2/text() }</FIELD2>
<FIELD3>{ $row1/FIELD3/text() }</FIELD3>
</MYTABLE>
}
</dataroot>

Postnext
david mareSubject: removing unwanted attributes resulting from database conversion to xml
Author: david mare
Date: 20 Feb 2008 09:45 PM
Thanks, and yes you are absolutely right, that will do the trick. However I was hoping not to have to code up all the tag names (this is just a small demo of a much larger more complex file).

Posttop
Minollo I.Subject: removing unwanted attributes resulting from database conversion to xml
Author: Minollo I.
Date: 20 Feb 2008 10:56 PM
You can clean up attributes using a function like this (remove all attributes named "attr1" and "attr2"):
declare function local:clean-element($el as element()) as element() {
element { $el } {
for $attr in $el/@*
let $attrName := local-name($attr)
return
if ($attrName != "attr1" and $attrName != "attr2") then $attr else ()
}
};

...assuming there are attributes you want to preserve; then you would do...
for $row1 in $table1
return
<MYTABLE>
{ local:clean-element($row1/FIELD1) }
{ local:clean-element($row1/FIELD2) }
{ local:clean-element($row1/FIELD3) }
</MYTABLE>

If you want to remove all attributes, it's of course even easier. And of course you don't need to explicitly list FIELD1, FIELD2, ... if you just want to return all of them (or if you just want to remove a few from a long list); you can use the same approach of local:clean-element().

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.