B
Blue Gecko
Hi all
I should fuse into an XML file the results dynamically generated by XSLT
transformations from some source files (attachment [2]).
The issue is that, obviously, each XSLT transformation generates its own
processing instructons (PIs, for example <?xml ...?>), so I end up (as
you can see in attachment [1]) with a sintactically-broken XML file.
Could you suggest me the most elegant way to resolve such a challenge?
Many thanks
[1] Resulting XML file:
<?xml version='1.0' encoding='iso-8859-1'?>
<siteMap>
<node href="index.page.teg">
<!-- This is the insertion point of the XSLT result from the
index.page.teg file -->
<?xml version="1.0" encoding="iso-8859-1"?>
<info/>
<node href="about/index.page.teg">
<!-- This is the insertion point of the XSLT result from the
about/index.page.teg file -->
<?xml version="1.0" encoding="iso-8859-1"?>
<info/>
</node>
</node>
</siteMap>
[2] Code recursively generating the node hierarchy:
/*
Note:
PrintWriter siteMapWriter is the writing stream of the resulting XML
file (see [1]).
*/
private void buildNodeList(
NodeList siteNodeList
)
{
for(
int index = 0;
index < siteNodeList.getLength();
index++
)
{
Node siteNode = siteNodeList.item(index);
String pageHref =
siteNode.getAttributes().getNamedItem("href").getNodeValue();
// Print the map node start!
siteMapWriter.print("<node href=\"" + pageHref + "\">");
File pageFile = new File(basePath + pageHref);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try
{
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(pageFile);
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(this.siteMapWriter);
pageInfoExtractor.transform(source, result);
}
//<snip content="catches"/>
// Print the map subnodes!
buildNodeList(
((Element)siteNode).getElementsByTagName("node")
);
// Print the map node end!
siteMapWriter.print("</node>");
}
}
I should fuse into an XML file the results dynamically generated by XSLT
transformations from some source files (attachment [2]).
The issue is that, obviously, each XSLT transformation generates its own
processing instructons (PIs, for example <?xml ...?>), so I end up (as
you can see in attachment [1]) with a sintactically-broken XML file.
Could you suggest me the most elegant way to resolve such a challenge?
Many thanks
[1] Resulting XML file:
<?xml version='1.0' encoding='iso-8859-1'?>
<siteMap>
<node href="index.page.teg">
<!-- This is the insertion point of the XSLT result from the
index.page.teg file -->
<?xml version="1.0" encoding="iso-8859-1"?>
<info/>
<node href="about/index.page.teg">
<!-- This is the insertion point of the XSLT result from the
about/index.page.teg file -->
<?xml version="1.0" encoding="iso-8859-1"?>
<info/>
</node>
</node>
</siteMap>
[2] Code recursively generating the node hierarchy:
/*
Note:
PrintWriter siteMapWriter is the writing stream of the resulting XML
file (see [1]).
*/
private void buildNodeList(
NodeList siteNodeList
)
{
for(
int index = 0;
index < siteNodeList.getLength();
index++
)
{
Node siteNode = siteNodeList.item(index);
String pageHref =
siteNode.getAttributes().getNamedItem("href").getNodeValue();
// Print the map node start!
siteMapWriter.print("<node href=\"" + pageHref + "\">");
File pageFile = new File(basePath + pageHref);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try
{
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(pageFile);
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(this.siteMapWriter);
pageInfoExtractor.transform(source, result);
}
//<snip content="catches"/>
// Print the map subnodes!
buildNodeList(
((Element)siteNode).getElementsByTagName("node")
);
// Print the map node end!
siteMapWriter.print("</node>");
}
}