Problem in inserting xml declaration while adding a doc into a collection
Monday, 12 September 2011 · 2 messages
MR
Murthy Raju12 Sep 2011 02:58 #
Hi,
I am newbie to Basex. I am trying to connect to BaseXJAXRX server from python and trying to add a document along with its xml declaration to a collection. The XML declaration is not getting stored. Here is the code snippet:
----
xml = '<?xml version="1.0" encoding="UTF-8"
?><Message><Product><Reference>2233</Reference><Product></Message>'
session = BaseXClient.Session(settings.BASEX_SERVER_IP,
settings.BASEX_SERVER_
PORT,
settings.BASEX_SERVER_USER,settings.BASEX_SERVER_USER)
session.execute('SET DBPATH '+ settings.XMLDB_FOLDER)
session.execute('OPEN ' + settings.XMLDB_NAME)
session.add("2233.xml", "", etree.tostring(xml, encoding="utf-8", xml_declaration=True))
input = "declare option output:omit-xml-declaration 'no';
collection('" + settings.XMLDB_NAME +
"')//Message[//Reference='2233']"
query = session.query(input)
query.init()
while query.more():
product = query.next()
print product
session.close()
----
'print product' results in the following:<Message><Product><Reference>2233</Reference><Product></Message>How do I ensure that the XML declaration is also stored? Is
omit-xml-declaration the answer? How do I set it while running "add" on BasexClient.Session?
Thanks
Murthy Raju
CG
Christian Grün12 Sep 2011 09:47 #
Dear Murthy,
thanks for your mail and the not-so-obvious problem. In BaseX (and other native XML databases), the XML declaration is not stored in the database, as all data is internally represented in the same encoding and XML version. To read the declaration when outputting
(“serializing”) the document, you need to specify the
omit-xml-declaration flag, which you've already noticed. Please find some more information on serialization parameters at:
http://docs.basex.org/wiki/Serialization
Feel free to ask for more,
Christian
Quoted text · Murthy Raju · 52 lines
On Mon, Sep 12, 2011 at 2:58 AM, Murthy Raju <murthyraju at gmail.com> wrote: > Hi, > > I am newbie to Basex. I am trying to connect to BaseXJAXRX server from > python and trying to add a document along with its xml declaration to > a collection. The XML declaration is not getting stored. Here is the > code snippet: > > ---- > > xml = '<?xml version="1.0" encoding="UTF-8" > ?><Message><Product><Reference>2233</Reference><Product></Message>' > > session = BaseXClient.Session(settings.BASEX_SERVER_IP, > settings.BASEX_SERVER_PORT, > settings.BASEX_SERVER_USER,settings.BASEX_SERVER_USER) > session.execute('SET DBPATH '+ settings.XMLDB_FOLDER) > session.execute('OPEN ' + settings.XMLDB_NAME) > session.add("2233.xml", "", etree.tostring(xml, encoding="utf-8", > xml_declaration=True)) > > > input = "declare option output:omit-xml-declaration 'no'; > collection('" + settings.XMLDB_NAME + > "')//Message[//Reference='2233']" > > query = session.query(input) > > query.init() > > while query.more(): > product = query.next() > print product > > session.close() > > ---- > > 'print product' results in the following: > > <Message><Product><Reference>2233</Reference><Product></Message> > > How do I ensure that the XML declaration is also stored? Is > omit-xml-declaration the answer? How do I set it while running "add" > on BasexClient.Session? > > Thanks > Murthy Raju > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Written for BaseX 6.7. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery