best approach to add dtd file into baseX
Thursday, 7 January 2016 · 4 messages
WY
Wang, Yvonne7 Jan 2016 01:33 #
Hi,
I have sample dtd file such as below, I want to add the dtd file as is in baseX.
Since the dtd file is not in xml format, there are currently two option I can thought about
1. Use TEXT as input format
When I add it using baseX client UI, I got following output. Since we just need store the dtd file and later get it back as is. So I can not use doc function to retrieve it back as is.
<text>
<line><dtd></line>
<line><!--</line>
<line><?xml encoding="UTF-8"?></line>
<line/>
<line> <tmpComment>Sample rng file comments</tmpComment></line>
<line/>
<line><!ELEMENT first (#PCDATA)></line>
<line/>
<line><!ELEMENT last (#PCDATA)></line>
<line/>
<line><!ELEMENT user (first,last)></line>
<line><!ATTLIST user</line>
<line> xmlns:xsi CDATA #FIXED 'http://www.w3.org/2001/XMLSchema-instance'</line>
<line> xsi:schemaLocation CDATA #FIXED 'http://ariba.com.com/Core_after_xsd.xsd'></line>
<line>--></line>
</text>2. Format it to xml using <dtd> <!-original data --> </dtd> when add, and remove those dtd and comment tag when download using doc() function.
And there is extra handling required for nested xml comment.
Is there any other better approach for adding dtd file which can be retrieved as its original content?
Thanks
Yvonne
=========================================================================================================================== Sample.dtd
<?xml encoding="UTF-8"?>
<!-- Sample rng file comments -->
<!ELEMENT first (#PCDATA)>
<!ELEMENT last (#PCDATA)><!ELEMENT user (first,last)>
<!ATTLIST user
xmlns:xsi CDATA #FIXED 'http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation CDATA #FIXED 'http://ariba.com.com/Core_after_xsd.xsd'>
CG
Christian Grün7 Jan 2016 09:00 #
Hi Yvonne,
The canonical solution is to store and retrieve your file as binary file [1]. Instead of
fn:doc, you can use db:retrieve to access this resource [1].
Hope this helps,
Christian
[1] http://docs.basex.org/wiki/DatabasesQuoted text · Yvonne · 118 lines
On Thu, Jan 7, 2016 at 1:33 AM, Wang, Yvonne <yvonne.wang at sap.com> wrote: > Hi, > > > > I have sample dtd file such as below, I want to add the dtd file as is in > baseX. > > > > Since the dtd file is not in xml format, there are currently two option I > can thought about > > > > 1. Use TEXT as input format > > > > When I add it using baseX client UI, I got following output. Since we just > need store the dtd file and later get it back as is. So I can not use doc > function to retrieve it back as is. > > > > <text> > > <line><dtd></line> > > <line><!--</line> > > <line><?xml encoding="UTF-8"?></line> > > <line/> > > <line> <tmpComment>Sample rng file > comments</tmpComment></line> > > <line/> > > <line><!ELEMENT first (#PCDATA)></line> > > <line/> > > <line><!ELEMENT last (#PCDATA)></line> > > <line/> > > <line><!ELEMENT user (first,last)></line> > > <line><!ATTLIST user</line> > > <line> xmlns:xsi CDATA #FIXED > 'http://www.w3.org/2001/XMLSchema-instance'</line> > > <line> xsi:schemaLocation CDATA #FIXED > 'http://ariba.com.com/Core_after_xsd.xsd'></line> > > <line>--></line> > > </text> > > > > 2. Format it to xml using <dtd> <!—original data --> </dtd> when > add, and remove those dtd and comment tag when download using doc() > function. > > And there is extra handling required for nested xml comment. > > > > Is there any other better approach for adding dtd file which can be > retrieved as its original content? > > > > Thanks > > > > Yvonne > > > > > > =========================================================================================================================== > > Sample.dtd > > > > <?xml encoding="UTF-8"?> > > > > <!-- Sample rng file comments --> > > > > <!ELEMENT first (#PCDATA)> > > > > <!ELEMENT last (#PCDATA)> > > > > <!ELEMENT user (first,last)> > > <!ATTLIST user > > xmlns:xsi CDATA #FIXED 'http://www.w3.org/2001/XMLSchema-instance' > > xsi:schemaLocation CDATA #FIXED 'http://ariba.com.com/Core_after_xsd.xsd'> > >
LV
Lizzi, Vincent7 Jan 2016 16:57 #
Out of curiosity, is it possible to work with (validate against) a DTD file stored as binary in BaseX? I imagine something like using a catalog to resolve DTD references in XML files to DTD files stored in BaseX might work.
Thanks,
Vincent
Quoted text · basex-talk-bounces at mailman.uni-konstanz.de · 130 lines
From: basex-talk-bounces at mailman.uni-konstanz.de [mailto:basex-talk-bounces at mailman.uni-konstanz.de] On Behalf Of Christian Grün Sent: Thursday, January 07, 2016 3:00 AM To: Wang, Yvonne <yvonne.wang at sap.com> Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] best approach to add dtd file into baseX Hi Yvonne, The canonical solution is to store and retrieve your file as binary file [1]. Instead of fn:doc, you can use db:retrieve to access this resource [1]. Hope this helps, Christian [1] http://docs.basex.org/wiki/Databases<http://docs.basex.org/wiki/Databases> On Thu, Jan 7, 2016 at 1:33 AM, Wang, Yvonne <yvonne.wang at sap.com<mailto:yvonne.wang at sap.com>> wrote: > Hi, > > > > I have sample dtd file such as below, I want to add the dtd file as is in > baseX. > > > > Since the dtd file is not in xml format, there are currently two option I > can thought about > > > > 1. Use TEXT as input format > > > > When I add it using baseX client UI, I got following output. Since we just > need store the dtd file and later get it back as is. So I can not use doc > function to retrieve it back as is. > > > > <text> > > <line><dtd></line> > > <line><!--</line> > > <line><?xml encoding="UTF-8"?></line> > > <line/> > > <line> <tmpComment>Sample rng file > comments</tmpComment></line> > > <line/> > > <line><!ELEMENT first (#PCDATA)></line> > > <line/> > > <line><!ELEMENT last (#PCDATA)></line> > > <line/> > > <line><!ELEMENT user (first,last)></line> > > <line><!ATTLIST user</line> > > <line> xmlns:xsi CDATA #FIXED > 'http://www.w3.org/2001/XMLSchema-instance<http://www.w3.org/2001/XMLSchema-instance>'</line> > > <line> xsi:schemaLocation CDATA #FIXED > 'http://ariba.com.com/Core_after_xsd.xsd'><http://ariba.com.com/Core_after_xsd.xsd'>></line> > > <line>--></line> > > </text> > > > > 2. Format it to xml using <dtd> <!—original data --> </dtd> when > add, and remove those dtd and comment tag when download using doc() > function. > > And there is extra handling required for nested xml comment. > > > > Is there any other better approach for adding dtd file which can be > retrieved as its original content? > > > > Thanks > > > > Yvonne > > > > > > =========================================================================================================================== > > Sample.dtd > > > > <?xml encoding="UTF-8"?> > > > > <!-- Sample rng file comments --> > > > > <!ELEMENT first (#PCDATA)> > > > > <!ELEMENT last (#PCDATA)> > > > > <!ELEMENT user (first,last)> > > <!ATTLIST user > > xmlns:xsi CDATA #FIXED 'http://www.w3.org/2001/XMLSchema-instance<http://www.w3.org/2001/XMLSchema-instance>' > > xsi:schemaLocation CDATA #FIXED 'http://ariba.com.com/Core_after_xsd.xsd<http://ariba.com.com/Core_after_xsd.xsd>'> > >
CG
Christian Grün7 Jan 2016 17:34 #
Hi Vincent,
Here is one way to do it:
let $binary := db:retrieve('db', 'schema.dtd')
let $schema := bin:decode-string($binary)
let $input := db:open('db', 'doc.xml')
return validate:dtd($input, $schema)Hope this helps,
Christian
Quoted text · Vincent · 151 lines
On Thu, Jan 7, 2016 at 4:57 PM, Lizzi, Vincent <Vincent.Lizzi at taylorandfrancis.com> wrote: > Out of curiosity, is it possible to work with (validate against) a DTD file > stored as binary in BaseX? I imagine something like using a catalog to > resolve DTD references in XML files to DTD files stored in BaseX might work. > > Thanks, > Vincent > > > From: basex-talk-bounces at mailman.uni-konstanz.de > [mailto:basex-talk-bounces at mailman.uni-konstanz.de] On Behalf Of Christian > Grün > Sent: Thursday, January 07, 2016 3:00 AM > To: Wang, Yvonne <yvonne.wang at sap.com> > Cc: basex-talk at mailman.uni-konstanz.de > Subject: Re: [basex-talk] best approach to add dtd file into baseX > > > > Hi Yvonne, > > The canonical solution is to store and retrieve your file as binary > file [1]. Instead of fn:doc, you can use db:retrieve to access this > resource [1]. > > Hope this helps, > Christian > > [1] http://docs.basex.org/wiki/Databases > > > On Thu, Jan 7, 2016 at 1:33 AM, Wang, Yvonne <yvonne.wang at sap.com> wrote: >> Hi, >> >> >> >> I have sample dtd file such as below, I want to add the dtd file as is in >> baseX. >> >> >> >> Since the dtd file is not in xml format, there are currently two option I >> can thought about >> >> >> >> 1. Use TEXT as input format >> >> >> >> When I add it using baseX client UI, I got following output. Since we just >> need store the dtd file and later get it back as is. So I can not use doc >> function to retrieve it back as is. >> >> >> >> <text> >> >> <line><dtd></line> >> >> <line><!--</line> >> >> <line><?xml encoding="UTF-8"?></line> >> >> <line/> >> >> <line> <tmpComment>Sample rng file >> comments</tmpComment></line> >> >> <line/> >> >> <line><!ELEMENT first (#PCDATA)></line> >> >> <line/> >> >> <line><!ELEMENT last (#PCDATA)></line> >> >> <line/> >> >> <line><!ELEMENT user (first,last)></line> >> >> <line><!ATTLIST user</line> >> >> <line> xmlns:xsi CDATA #FIXED >> 'http://www.w3.org/2001/XMLSchema-instance'</line> >> >> <line> xsi:schemaLocation CDATA #FIXED >> 'http://ariba.com.com/Core_after_xsd.xsd'></line> >> >> <line>--></line> >> >> </text> >> >> >> >> 2. Format it to xml using <dtd> <!—original data --> </dtd> when >> add, and remove those dtd and comment tag when download using doc() >> function. >> >> And there is extra handling required for nested xml comment. >> >> >> >> Is there any other better approach for adding dtd file which can be >> retrieved as its original content? >> >> >> >> Thanks >> >> >> >> Yvonne >> >> >> >> >> >> >> =========================================================================================================================== >> >> Sample.dtd >> >> >> >> <?xml encoding="UTF-8"?> >> >> >> >> <!-- Sample rng file comments --> >> >> >> >> <!ELEMENT first (#PCDATA)> >> >> >> >> <!ELEMENT last (#PCDATA)> >> >> >> >> <!ELEMENT user (first,last)> >> >> <!ATTLIST user >> >> xmlns:xsi CDATA #FIXED 'http://www.w3.org/2001/XMLSchema-instance' >> >> xsi:schemaLocation CDATA #FIXED 'http://ariba.com.com/Core_after_xsd.xsd'> >> >>
Written for BaseX 8.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery