Hi Michael!

Thanks for helping us with the line Wrapping issue, We haven’t notice this problem until only today that we are doing a regression test with our system.

Below code is the java codes that we had isolated that is causing a major problem to use. When we pass an xml

Example

<element>

<data

id="12"

lot="134"

/>

<data

id="13" lot="A"

/>

</element>

Some of the elements are in multiple rows, but we need to maintain or preserve it’s structure when we do the schema validation.

 

The output was:

<element>

<data id="12" lot="134"/>

<data id="13" lot="A"/>

</element>

 

But we still need the original structure, Basically we need the XdmNode to be passed on the XML Pipeline “Calabash” for further processing.

 

 

Java codes

 

Processor processor = new Processor(false);

DocumentBuilder builder = processor.newDocumentBuilder();

try

{

// Ready Back XML

XdmNode xdmNode = builder.build(new StreamSource(new FileInputStream("c:/saxson/error.xml")));

StringWriter sw = new StringWriter();

 

// create output Serializer

Serializer out = new Serializer();

out.setOutputProperty(Serializer.Property.INDENT, "no");

out.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes");

// set output stream

out.setOutputWriter(sw);

 

// Ready Back XML

XQueryCompiler compiler = processor.newXQueryCompiler();

XQueryExecutable exp = compiler.compile(".");

XQueryEvaluator eval = exp.load();

eval.setContextItem(xdmNode);

eval.run(out);

String serxml = sw.toString();

System.out.println(serxml);

}

catch (Exception ex)

{

ex.printStackTrace();

}

 

 

Sincerely,

Gerald G. Ternola

IT-Application Center of Excellence(ACE)

PEIT-ACE

 

From: Michael Kay [mailto:mike@saxonica.com]
Sent: Wednesday, January 27, 2010 4:25 PM
To: Ternola, Gerald
Subject: RE: Line Wrapping of Saxon

 

The toString() method has to choose a serialization method from the many possibilities available, and the one chosen is designed to give good results for example when the node is shown in a debugger. The serialization options that it uses are documented in the API specification, so there is no reason for you to be "amazed". If you want control over serialization, don't use the toString() method, instead use Processor.writeXdmValue() supplying a Serializer as the destination: this allows you to set your own serialization parameters such as

 

serializer.setOutputProperty(Serializer.Property.INDENT, "no")

 

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay

 

PS: if you have questions in future, I would be grateful if you could post them to the saxon-help mailing list or forum rather than to my personal email address.

 

 

 


From: Ternola, Gerald [mailto:g-ternola@ti.com]
Sent: 27 January 2010 02:08
To: mike@saxonica.com
Subject: Line Wrapping of Saxon

Hi Mike,

                I got a question regarding the line wrapping of saxon. I tried to parse an xml and put it to an XdmNode then when I test it to see if it contains the original format of the xml being entered, I was amazed that it was reformatted but the content is the same.

                Here is the problem our application needs to read the original Xml as is and not formatted “pretty print”, can you suggest any fix for this one.

 

 

Processor processor = new Processor(false);

DocumentBuilder builder = processor.newDocumentBuilder();

XdmNode xdmNode=builder.build(new File("c:/testxerces/CHAR-F7_1218C021.M7NOW_F771683c_20091201155300_wfcfg.xml"));

System.out.println(xdmNode.toString());

 

                Thanks J

 

Sincerely,

Gerald G. Ternola

IT-Application Center of Excellence(ACE)

PEIT-ACE