Hi all, I have this file (simplified):
<r:root xmlns:r="r" xmlns:x="x" xmlns:y="y" xmlns:z="z"> <x:x/> <y:y/> <z:z/> </r:root>
I have created a new database from that file (using Java API) and checked in the GUI that the file's contents are as "expected" by querying the root of the database.
Now, when using the QueryProcessor API to query the root of the database, I will get this re-structured namespaces xml:
<r:root xmlns:r="r"> <x:x xmlns:x="x"/> <y:y xmlns:y="y"/> <z:z xmlns:z="z"/> </r:root>
How can I prevent this behavior? Is there a setting to provide to the QueryProcessor?
Thanks!
Hi Erdal,
Sorry, I need more information in order to reproduce this. Could you provide us with an SSCCE?
Christian
On Wed, Nov 19, 2014 at 8:37 PM, Erdal Karaca erdal.karaca.de@gmail.com wrote:
Hi all, I have this file (simplified):
<r:root xmlns:r="r" xmlns:x="x" xmlns:y="y" xmlns:z="z"> <x:x/> <y:y/> <z:z/> </r:root>
I have created a new database from that file (using Java API) and checked in the GUI that the file's contents are as "expected" by querying the root of the database.
Now, when using the QueryProcessor API to query the root of the database, I will get this re-structured namespaces xml:
<r:root xmlns:r="r"> <x:x xmlns:x="x"/> <y:y xmlns:y="y"/> <z:z xmlns:z="z"/> </r:root>
How can I prevent this behavior? Is there a setting to provide to the QueryProcessor?
Thanks!
Hi Christian, I have extracted an SSCCE:
public static void main(String[] args) throws Exception { String origXML = "<r:root xmlns:r='r' xmlns:x='x' xmlns:y='y' xmlns:z='z'><x:x/><y:y/><z:z/></r:root>"; Context dbCtx = new Context();
// create DB { CreateDB cmd = new CreateDB("test-db", origXML); cmd.execute(dbCtx); }
// query root of doc { QueryProcessor query = new QueryProcessor("/", dbCtx); Value value = query.value(); Node node = (Node)value.toJava();
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(); javax.xml.transform.Transformer transformer =
javax.xml.transform.TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes"); transformer.transform(new javax.xml.transform.dom.DOMSource(node), new javax.xml.transform.stream.StreamResult(out)); System.out.println(out.toString()); } }
The resulting output is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <r:root xmlns:r="r"> <x:x xmlns:x="x"/> <y:y xmlns:y="y"/> <z:z xmlns:z="z"/> </r:root>
As said, the expected result is:
<r:root xmlns:r="r" xmlns:x="x" xmlns:y="y" xmlns:z="z"> <x:x/> <y:y/> <z:z/> </r:root>
2014-11-19 21:21 GMT+01:00 Christian Grün christian.gruen@gmail.com:
Hi Erdal,
Sorry, I need more information in order to reproduce this. Could you provide us with an SSCCE?
Christian
On Wed, Nov 19, 2014 at 8:37 PM, Erdal Karaca erdal.karaca.de@gmail.com wrote:
Hi all, I have this file (simplified):
<r:root xmlns:r="r" xmlns:x="x" xmlns:y="y" xmlns:z="z"> <x:x/> <y:y/> <z:z/> </r:root>
I have created a new database from that file (using Java API) and
checked in
the GUI that the file's contents are as "expected" by querying the root
of
the database.
Now, when using the QueryProcessor API to query the root of the
database, I
will get this re-structured namespaces xml:
<r:root xmlns:r="r"> <x:x xmlns:x="x"/> <y:y xmlns:y="y"/> <z:z xmlns:z="z"/> </r:root>
How can I prevent this behavior? Is there a setting to provide to the QueryProcessor?
Thanks!
BTW: I am using BaseX 7.7
2014-11-19 21:49 GMT+01:00 Erdal Karaca erdal.karaca.de@gmail.com:
Hi Christian, I have extracted an SSCCE:
public static void main(String[] args) throws Exception { String origXML = "<r:root xmlns:r='r' xmlns:x='x' xmlns:y='y'
xmlns:z='z'><x:x/><y:y/><z:z/></r:root>"; Context dbCtx = new Context();
// create DB { CreateDB cmd = new CreateDB("test-db", origXML); cmd.execute(dbCtx); } // query root of doc { QueryProcessor query = new QueryProcessor("/", dbCtx); Value value = query.value(); Node node = (Node)value.toJava(); java.io.ByteArrayOutputStream out = new
java.io.ByteArrayOutputStream(); javax.xml.transform.Transformer transformer =
javax.xml.transform.TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes"); transformer.transform(new javax.xml.transform.dom.DOMSource(node), new javax.xml.transform.stream.StreamResult(out)); System.out.println(out.toString()); } }
The resulting output is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<r:root xmlns:r="r"> <x:x xmlns:x="x"/> <y:y xmlns:y="y"/> <z:z xmlns:z="z"/> </r:root>
As said, the expected result is:
<r:root xmlns:r="r" xmlns:x="x" xmlns:y="y" xmlns:z="z"> <x:x/> <y:y/> <z:z/> </r:root>
2014-11-19 21:21 GMT+01:00 Christian Grün christian.gruen@gmail.com:
Hi Erdal,
Sorry, I need more information in order to reproduce this. Could you provide us with an SSCCE?
Christian
On Wed, Nov 19, 2014 at 8:37 PM, Erdal Karaca erdal.karaca.de@gmail.com wrote:
Hi all, I have this file (simplified):
<r:root xmlns:r="r" xmlns:x="x" xmlns:y="y" xmlns:z="z"> <x:x/> <y:y/> <z:z/> </r:root>
I have created a new database from that file (using Java API) and
checked in
the GUI that the file's contents are as "expected" by querying the root
of
the database.
Now, when using the QueryProcessor API to query the root of the
database, I
will get this re-structured namespaces xml:
<r:root xmlns:r="r"> <x:x xmlns:x="x"/> <y:y xmlns:y="y"/> <z:z xmlns:z="z"/> </r:root>
How can I prevent this behavior? Is there a setting to provide to the QueryProcessor?
Thanks!
It may be easier to stick with the built-in serializer of BaseX (it's faster anyway):
Old:
java.io.ByteArrayOutputStream out = new
java.io.ByteArrayOutputStream(); javax.xml.transform.Transformer transformer =
javax.xml.transform.TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes"); transformer.transform(new javax.xml.transform.dom.DOMSource(node), new javax.xml.transform.stream.StreamResult(out)); System.out.println(out.toString());
New:
System.out.println(value.serialize());
Alternative:
ByteArrayOutputStream ao = new ByteArrayOutputStream(); Serializer ser = query.getSerializer(ao); for(Item item : value) ser.serialize(item); System.out.println(ao);
basex-talk@mailman.uni-konstanz.de