Nira Shavitt

Greenhorn
+ Follow
since Jul 26, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Nira Shavitt

hi,

I'm using a transformer to write xsl file (using a default copy transformation) but the transformer do resolve the entities although the code explicitly asks to avoid resolving entities.

For example - the line
<xsl:value-of select="concat('http', '://',.)"
is copied and looks like:
<xsl:value-of select="concat('http', '://',.)"/>

here's the code I'm using:

// Step 1: create a DocumentBuilderFactory and configure it
m_documentBuilderFactory = DocumentBuilderFactory.newInstance();

m_documentBuilderFactory.setExpandEntityReferences(false);
m_documentBuilderFactory.setNamespaceAware(true);

try
{
m_documentBuilder = m_documentBuilderFactory.newDocumentBuilder();
}
catch (ParserConfigurationException pce)
{
System.err.println(pce);
System.exit(1);
}
hi,

I'm using xsl for a transformer to write a DOM to a file, and I'm getting a problem - it does not indent the xml. Does anyone know how to indent the xml?

I used the following code for the transformer:

transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
hi,

I'm using xsl for a transformer to write a a DOM to a file, and I'm getting a problem - it eliminates the comments. Does anyone know how to reserve them?

This is the transformer I have:

private static final String TRANSFORMER_STRING = "<?xml version=\"1.0\"?>" +
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:fo=\"http://www.w3.org/1999/XSL/Format\" xmlns:html=\"http://www.w3.org/TR/REC-html40\" version=\"1.0\" stl:optimize=\"true\" stl:version=\"0.6\">" +
"<xsl:output encoding=\"ISO-8859-1\" method=\"xml\" indent=\"no\"/>" +
"<xsl:template match=\"*|@*\">" +
"<xsl:copy>" +
"<xsl:apply-templates select=\"*|@*|text()\"/>" +
"</xsl:copy>" +
"</xsl:template>" +
"</xsl:stylesheet>";
hi,

I was using crimson parser for parsing xml files, and now I'm trying to switch to the parser exists in jdk 1.4 (SAXParser). I have a few problems, one of them is that the new parser eliminates comments that are in the xml file, or at least doesn't write them back to the new xml file.

Any idea?
hi,

I have a small program that reads an XML and writes it. There are some entities in the xml attributes, which I don't want to be resolved, but justto be written back as they appear in the source file. I'm using the DocumentBuilderFactory class and it's method setExpandEntityReferences(false) to avoid the expansions of the entities, but it still resolves the entities within the attributes. Why? What's wrong? I'm working xerces.jar (2.7.1), xalan.jar(2.7.0) and xml-apis(2.7.1) and jdk 1.3.1.

there's the code:

public static void main(String[] args) {

if (args.length <= 0) {
System.out.println("Usage: java EntityLister fileName");
return;
}

String fileName = args[0];
File xmlFile = null;
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

// By default JAXP does not include entity reference nodes
// in the tree. You have to explicitly request them by
// telling DocumentBuilderFactory not to expand entity
// references.
factory.setExpandEntityReferences(false);

DocumentBuilder parser = factory.newDocumentBuilder();

// Read the file
xmlFile = new File(fileName);

// construct the document
Document document = parser.parse(xmlFile);

DOMSource domSource = new DOMSource(document);
StreamSource xslSource = new StreamSource("transformer.xsl"); // XSL for empty transformation

TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer(xslSource);

StreamResult streamResult = new StreamResult(new OutputStreamWriter(new FileOutputStream("result.xml"),"ISO-8859-1"));

transformer.transform(domSource, streamResult);

}
catch (SAXException e) {
System.out.println(xmlFile + " is not well-formed.");
}
catch (IOException e) {
System.out.println(
"Due to an IOException, the parser could not read " + xmlFile
);
}
catch (FactoryConfigurationError e) {
System.out.println("Could not locate a factory class");
}
// catch (ParserConfigurationException e) {
// System.out.println("Could not locate a JAXP parser");
// }
catch(Exception e) {
System.out.println("Exception!!! "+ e.toString());
}
} // end main
}

so if the input file is:

<?xml version="1.0" encoding="UTF-8"?>

<Tokenization>
<StartWordChars>
<Char From="぀" To="ゟ"/>
<Char From="゠" To="ヿ"/>
<Char From="豈" To="﫿"/>
<Char From="一" To="龯"/>
<Char From="丽" To="𯨟"/>
</StartWordChars>

<EndWordChars>
<Char From="぀" To="ゟ"/>
<Char From="゠" To="ヿ"/>
<Char From="豈" To="﫿"/>
<Char From="一" To="龯"/>
<Char From="丽" To="𯨟"/>
</EndWordChars>

<NonDelimeterChars>
<Char From="぀" To="ゟ"/>
<Char From="゠" To="ヿ"/>
<Char From="豈" To="﫿"/>
<Char From="一" To="龯"/>
<Char From="丽" To="𯨟"/>
<Char Value="."/>
<Char Value="­"/>
</NonDelimeterChars>
</Tokenization>

I get the output file:

<?xml version="1.0" encoding="UTF-8"?><Tokenization>
<StartWordChars>
<Char From="?" To="?"/>
<Char From="?" To="?"/>
<Char From="?" To="?"/>
<Char From="?" To="?"/>
<Char From="丽?" To="𯨟?"/>
</StartWordChars>

<EndWordChars>
<Char From="?" To="?"/>
<Char From="?" To="?"/>
<Char From="?" To="?"/>
<Char From="?" To="?"/>
<Char From="丽?" To="𯨟?"/>
</EndWordChars>

<NonDelimeterChars>
<Char From="?" To="?"/>
<Char From="?" To="?"/>
<Char From="?" To="?"/>
<Char From="?" To="?"/>
<Char From="丽?" To="𯨟?"/>
<Char Value="."/>
<Char Value="�"/>
</NonDelimeterChars>
</Tokenization>

anyone can help?
hi,

yap, I had the same problem and I couldn't resolve it. I build an ant build file and used it whenever I wanted to build the project, but then Eclipse build all the files for every minor change. I couldn't get any explanation for this problem. sorry.

Nira Shavitt
here is .classpath:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry sourcepath="X:/Titan/TOOLS/junit3.8.1/src.jar" kind="lib" path="X:/Titan/TOOLS/junit3.8.1/junit.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/BusinessLogic/Lib/Ext/xml-apis.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/BusinessLogic/Lib/Ext/concurrent.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/BusinessLogic/Lib/Ext/jce.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/BusinessLogic/Lib/Ext/jmxri.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/BusinessLogic/Lib/Ext/log4j.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/BusinessLogic/Lib/Ext/websphere/wsexception.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/BusinessLogic/Lib/Ext/xalan.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/BusinessLogic/Lib/Ext/websphere/admin.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/BusinessLogic/Lib/corba.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/Tomcat/common/lib/servlet.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/BusinessLogic/Lib/Endorsed/crimson.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/JBoss/client/jboss-j2ee.jar"/>
<classpathentry kind="lib" path="X:/Titan/directory_root/System/Tomcat/common/lib/ant.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>


Here is .project:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Framework</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>


thnaks for trying...
Nira Shavitt.

[edited to show full XML]
[ August 29, 2004: Message edited by: Jeanne Boyarsky ]
well, yes, the Build path is set correct.

Any other idea?

Nira Shavitt.
great! I was looking for those key bindings too.

CRTL+Shift+T - doesn't work in Eclipse 3.0, right? What else?
CRTL+Shift+R - works fine.

Nira Shavitt.
I had the same problem and I just added the debug option to javac ant task, and it was resolved. just add 'debug="true"' to javac and try again.
As you use Ant for the compilation, the settings of the eclipse does not take effect, this is why you have to add it to ant task explicitly.
How exactly I should use the eclipse compiler to compile incrementaly?

Should I check the 'Build automatically' on and use my ant file only for building the jar? or I should turn off the 'build Automatically' and use 'Build Project' once in a while? When I click on Build Project, it looks like nothing happens. Also Build All didn't compile my sources...

Any idea?
hi,

I've noticed that Eclipse removes all class files in the following cases:

1) Whenever I save a source file (and 'Build Automatically' is on) Eclpise runs 'Building workspace...' (you can see it on the lower right corner of eclpise), and this process actually removes all the class files.
So when I choose ant target to compile my java classes it compiles ALL the files although I saved only one file.

2) If I turn 'Build Automatically' to off, then Eclipse run the 'Building Workspace' only when I select an ant target to build the project. so Again, all the class files are removed just before I choose to compile them, so again, I'm compiling all the sources!!!

Anyone knows why it removes all the class files, and how to solve thsi problem? I can't have partial compilation now.

thanks,
Nira.
hi,

1) I work with Eclipse3.0 and I noticed that if I selected the 'Build Automatically' feature under the 'Project' menu, then whenever I save a source file, the Eclipse runs the 'Build workbench' (can see it on the right lower corner of Eclipse) and this causes removing all the class files of the project. So whenever I save a source, If I run Ant after that to build the project, it compiles all the sources. Why?

2) If I disable the 'Build Automatically' feature, after saving a source file, no class file is removed. However, when I launch Ant thru the Eclipse, this, again, runs the 'rebuild workbench' which removes all the class files, and again, I'm compiling all the sources, although I changed only a few of them. Why?

3) How can I use Ant with Eclpise and still not have recompiling all the sources whenever I choose to build the project with Ant?

thanks,
Nira.
I made it! I had to add the missing jars to the Ant classpath! not to the project classpath. Under 'External Tools...'->Ant Build -> project build.xml-> classpath, I added crimson.jar and xml-apis.jar. Then Ant manages to run thru Eclipse3.0 which is using jdk 1.3.1. for compilation.
Sorry, I ment that I added the jar to the project build path. But, as I mentioned, it did not solve the problem.

Any other idea?

tx,
Nira