adding parent to xml doc in perl - perl

I have a problem of adding parent to the xml document. I got xml:
<book id="bk104">
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-03-10</publish_date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
and I want to add parent tag to the book so it would be:
<library>
<book id="bk104">
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-03-10</publish_date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
</library>
I'm using XML::LIBXML, I've tried to get root
my $root = $doc->getDocumentElement;
and create new element
my $new_element= $doc->createElement("library");
and then
$root->insertBefore($new_element,undef);
Finally :
my $root = $doc->getDocumentElement;
my $new_element= $doc->createElement("library");
$parent = $root->parentNode;
$root->insertBefore($new_element,$parent);
but it wont work. Also tried to find parent of root which returns header node, and then addchild but it does not work either.

Try this piece:
open my $in, '<:encoding(utf-8)', 'in.xml';
my $document = XML::LibXML->load_xml(IO => $in);
my $root = $document->documentElement();
my $new_root = $document->createElement('library');
$new_root->appendChild($root);
$document->setDocumentElement($new_root);
open my $out, '>:encoding(utf-8)', 'out.xml';
print $out $document->toString();
It creates new_root element, appends root element to new_root as a child and set new_root element as root element for document.

You need to create a new, empty library element and set it as the new root element of the document. Then add the old root as a new child.
use strict;
use warnings;
use XML::LibXML;
my $doc = XML::LibXML->load_xml(string => << '__END_XML__');
<book id="bk104">
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-03-10</publish_date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
__END_XML__
my $book = $doc->documentElement;
my $library = $doc->createElement('library');
$doc->setDocumentElement($library);
$library->appendChild($book);
print $doc->toString(1);
output
<?xml version="1.0"?>
<library>
<book id="bk104">
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-03-10</publish_date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
</library>

Related

Modify the Outlook CustomUI XML by powershell

friends. I want to check every of my company users' outlook customUI configuration file. Delete 2 UI buttons if any. I am trying to do it by powershell. But failed to do so. Any advice for my script?
Below is the XML content of olkexpplorer.officeUI. I need to check & delete the items in blockquotes in case they are existed in the configuration file.
<mso:customUI xmlns:x1="Microsoft.Forefront.SpamReporterAddin.Connect" xmlns:mso="http://schemas.microsoft.com/office/2009/07/customui">
<mso:ribbon>
<mso:qat />
<mso:tabs>
<mso:tab idQ="mso:TabMail">
<mso:group id="mso_c1.45620CF" label="Phishing Report" imageMso="TrustCenter" autoScale="true"
<mso:control idQ="x1:ExplorerPhishReportMenuButton" imageMso="TrustCenter" visible="true"/>
</mso:group>
> <mso:group id="mso_c2.14817EBA" label="Junk" autoScale="true">
> <mso:control idQ="x1:ExplorerSpamReportMenuButton" visible="true" />
> <mso:control idQ="x1:ExplorerPhishReportMenuButton" imageMso="GreenBall" visible="true" />
> </mso:group>
</mso:tab>
</mso:tabs>
</mso:ribbon>
</mso:customUI>
Here is my script
$input = [xml](Get-Content -Path “$path_to_office\olkexplorer.officeUI”)
$deletenames="mso_c2.14817EBA"
($input.customUI.ChildNodes |Where-object { $deletenames -contains $_.Name}) | ForEach-
Object{[void]$_.ParentNode.RemoveChild($_)}
$input.save(“$path_to_office\new.officeUI”)
First of all, it is not clear how the ribbon XML looks like after running your code:
$input.save(“$path_to_office\new.officeUI”)
Anyway, you can do any modifications until the ribbon XML is loaded by the host application. At runtime, you may consider using callbacks where they are available and call the IRIbbonUI.Invalidate or IRibbonUI.InvalidateControl methods to get your custom UI invalidated and callbacks triggered. Here is what MSDN states:
For each of the callbacks the add-in implements, the responses are cached. For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in-place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method.
The problem with your approach is that ChildNodes() only returns the immediate child nodes and not all child nodes (and using $input as a variable name is not considered a good practice anyway because its a reserved variable name).
So instead of ChildNodes() I would access the child node directly like so
$input.customUI.ribbon.tabs.tab.group | where-object { $DeleteNames -contains $_.id}
I would prefer the System.Xml.Linq classes like XDocument and XElement over the [xml] type alias because they make dealing with Xml inside a PowerShell script a little more convenient.
if this is the input xml:
$XmlCode = #'
<mso:customUI xmlns:mso="http://schemas.microsoft.com/office/2009/07/customui">
<mso:ribbon>
<mso:qat><mso:sharedControls>
<mso:control idQ="mso:FileNewDefault" visible="false"/>
<mso:control idQ="mso:FileOpen" visible="false"/>
<mso:control idQ="mso:FileSave" visible="true"/>
<mso:control idQ="mso:FileSendAsAttachment" visible="false"/>
<mso:control idQ="mso:FilePrintQuick" visible="false"/>
<mso:control idQ="mso:SpellingAndGrammar" visible="false"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:Undo" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:RedoOrRepeat" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:TableDrawTable" visible="false"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:FileOpenRecentFile" visible="false"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:FontDialog" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:FontSizeDecreaseWord" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:FontSize" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:PageSetupDialog" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:PrintPreviewAndPrint" visible="true"/>
</mso:sharedControls>
</mso:qat>
</mso:ribbon>
</mso:customUI>
'#
the following Powershell commands would remove all mso:control nodes with visible="false":
using namespace System.Xml.Linq
Add-Type -Assembly System.Xml.Linq
$xmlCode = "<<as shown above>>"
$xRoot = [XDocument]::Parse($xmlCode)
$msoNs = [XNamespace]::get("http://schemas.microsoft.com/office/2009/07/customui")
$DeleteNodes = $xRoot.Descendants($msoNs + "control").where{$_.Attribute("visible").Value -eq "false"}
$DeleteNodes.ForEach{$_.Remove()}
$xRoot.ToString()
# Save the new xml
$XmlPath = [System.IO.Path]::GetTempFileName()
$xRoot.Save($XmlPath)
XDocument has a Load() method for loading a xml file directly so there is no need to use the Parse() method (I was using for the sake of this example).
The only small drawback comparing to [xml] is that you have to consider namespaces.

How to deal with nested xml-collections in ETL of OrientDB?

I followed the samples at OrientDBs manual to extract data from a xml collection (2nd sample) and load it into a OrientDB graph database: it worked.
But now i stuck and don't know, how to describe the oetl-configuration (json-File), if I change the samples source data that it looks like (and meets my requirements) - nest a <ADD>-Section:
<?xml version="1.0" encoding="UTF-8"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<ADD>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</ADD>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<ADD>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</ADD>
</CD>
</CATALOG>
Does anybody know, how to write the configuration. The following doesn't work, and the ADD field in my graph database is an empty string:
...
"extractor" :
{ "xml":
{
"rootNode": "CATALOG.CD",
"tagsAsAttribute": ["CATALOG.CD"]
}
},
...
Thanks for your help!
Best

How to create a document and fill it with textboxes based on x and y coords or pixels?

Im trying to create a template to print some information on a blank document based in coordinates or pixels or cm, wtv is possible.
why? I have some accounting forms which is to bad fill it manual. Im wondering if it is possible to create a function with some parameters related to the text box positions in document.
eg. txtName goes to (3,15) position in a document. It may be necessary define the size of document
If it is possible, what language you recommend?
Yes, it is possible.
If you use Microsoft Word to insert a text box into a blank document, then save it, and inspect the resulting docx, you'll see Word inserts the text box in 2 formats:
<mc:AlternateContent>
<mc:Choice Requires="wps">
<w:drawing>
<wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251659264" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="44014479" wp14:editId="7FACADD8">
<wp:simplePos x="0" y="0"/>
<wp:positionH relativeFrom="column">
<wp:align>center</wp:align>
</wp:positionH>
<wp:positionV relativeFrom="paragraph">
<wp:posOffset>0</wp:posOffset>
</wp:positionV>
<wp:extent cx="2374265" cy="1403985"/>
<wp:effectExtent l="0" t="0" r="22860" b="23495"/>
<wp:wrapTopAndBottom/>
<wp:docPr id="307" name="Text Box 2"/>
<wp:cNvGraphicFramePr>
<a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
</wp:cNvGraphicFramePr>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
<wps:wsp>
<wps:cNvSpPr txBox="1">
<a:spLocks noChangeArrowheads="1"/>
</wps:cNvSpPr>
<wps:spPr bwMode="auto">
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="2374265" cy="1403985"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
<a:solidFill>
<a:srgbClr val="FFFFFF"/>
</a:solidFill>
<a:ln w="9525">
<a:solidFill>
<a:srgbClr val="000000"/>
</a:solidFill>
<a:miter lim="800000"/>
<a:headEnd/>
<a:tailEnd/>
</a:ln>
</wps:spPr>
<wps:txbx>
<w:txbxContent>
<w:p w:rsidR="006C2E97" w:rsidRDefault="006C2E97">
<w:proofErr w:type="gramStart"/>
<w:r>
<w:t>YOUR CONTENT GOES HERE</w:t>
</w:r>
</w:p>
</w:txbxContent>
</wps:txbx>
<wps:bodyPr rot="0" vert="horz" wrap="square" lIns="91440" tIns="45720" rIns="91440" bIns="45720" anchor="t" anchorCtr="0">
<a:spAutoFit/>
</wps:bodyPr>
</wps:wsp>
</a:graphicData>
</a:graphic>
<wp14:sizeRelH relativeFrom="margin">
<wp14:pctWidth>40000</wp14:pctWidth>
</wp14:sizeRelH>
<wp14:sizeRelV relativeFrom="margin">
<wp14:pctHeight>20000</wp14:pctHeight>
</wp14:sizeRelV>
</wp:anchor>
</w:drawing>
</mc:Choice>
<mc:Fallback>
<w:pict>
<v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe">
<v:stroke joinstyle="miter"/>
<v:path gradientshapeok="t" o:connecttype="rect"/>
</v:shapetype>
<v:shape id="Text Box 2" o:spid="_x0000_s1026" type="#_x0000_t202" style="position:absolute;margin-left:0;margin-top:0;width:186.95pt;height:110.55pt;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:center;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top" >
<v:textbox style="mso-fit-shape-to-text:t">
<w:txbxContent>
<w:p w:rsidR="006C2E97" w:rsidRDefault="006C2E97">
<w:r>
<w:t>YOUR CONTENT GOES HERE</w:t>
</w:r>
</w:p>
</w:txbxContent>
</v:textbox>
<w10:wrap type="topAndBottom"/>
</v:shape>
</w:pict>
</mc:Fallback>
</mc:AlternateContent>
</w:r>
You can use either the w:drawing or the w:pict syntax. I quite like w:pict with its #style
As a first step you'll want to play in Word with how the boxes are positioned - I guess you want them positioned against the page, not a paragraph.
Then its just a matter of replicating the XML in your choice of language.
You could:
unzip, manipulate, then rezip
doing the manipulation with XML aware tool
or doing the manipulation without that
or use a lib, such as:
for .NET, Microsoft's Open XML SDK
for Java, POI, docx4j
for C, libopc
etc...

ASP.NET 1.1 - XPathNavigator OuterXml equivalent

I'm working with the Google Maps API to do GeoCode lookups in 1.1 and I'm running into a brick wall with the XPathNavigator object.
I need to create a "sub-navigator" so that we can perform global xpath searches for nodes (e.g. //adr:PostalCodeNumber) because the xml schema changes depending upon the accuracy of the Address returned.
Here's a sample response:
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
<name>2601 S. McKenzie Street </name>
<Status>
<code>200</code>
<request>geocode</request>
</Status>
<Placemark id="p1">
<address>2601 S McKenzie St, Foley, AL 36535, USA</address>
<AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>AL</AdministrativeAreaName><Locality><LocalityName>Foley</LocalityName><Thoroughfare><ThoroughfareName>2601 S McKenzie St</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>36535</PostalCodeNumber></PostalCode></Locality></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="30.3733653" south="30.3706673" east="-87.6817548" west="-87.6844528" />
</ExtendedData>
<Point><coordinates>-87.6831038,30.3720163,0</coordinates></Point>
</Placemark>
<Placemark id="p2">
<address>2601 S McKenzie St, Gulf Shores, AL 36542, USA</address>
<AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Country> <CountryNameCode>US</CountryNameCode><CountryName>USA</CountryName><AdministrativeArea><AdministrativeAreaName>AL</AdministrativeAreaName><Locality><LocalityName>Gulf Shores</LocalityName><Thoroughfare><ThoroughfareName>2601 S McKenzie St</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>36542</PostalCodeNumber></PostalCode></Locality></AdministrativeArea></Country></AddressDetails>
<ExtendedData>
<LatLonBox north="30.3093758" south="30.3066778" east="-87.6818443" west="-87.6845423" />
</ExtendedData>
<Point><coordinates>-87.6832047,30.3080269,0</coordinates></Point>
</Placemark>
</Response></kml>
I've got this 2.0 block of code and I'm trying to find a 1.1 equivalent for the OuterXml property:
private XPathNavigator CreateSubNavigator(XPathNavigator nav)
{
using (StringReader reader = new StringReader(nav.OuterXml))
{
XPathDocument doc = new XPathDocument(reader);
return doc.CreateNavigator();
}
}
I found this blog article, but the links to the SerializableXPathNavigator source are dead. =(
http://www.tkachenko.com/blog/archives/000155.html
Forgive me for my noobness, but how would I go about writing my own SerializableXPathNavigator class with my own OuterXml method?
Thanks so much for your help.

How to insert schemalocation in a xml document via DOM

i create a xml document with JAXP and search a way to insert the schemalocation.
At the moment my application produces:
<?xml version="1.0" encoding="UTF-8"?>
<root>
...
</root>
But i need:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="namespaceURL"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="namespaceURL pathToMySchema.xsd">
...
</root>
My code:
StreamResult result = new StreamResult(writer);
Document doc = getDocument();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty(OutputKeys.METHOD, "xml");
trans.setOutputProperty(OutputKeys.VERSION, "1.0");
trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
DOMSource source = new DOMSource(depl.getAsElement(doc));
trans.transform(source, result);
Thanks for your time,
Kasten
In XML data model namespace nodes are not actually read from parent element but each element has its own namespace nodes. Therefore simply adding a new default namespace to root element doesn't work but results in a document like this
<root xmlns="namespaceURL">
<child xmlns=""/>
...
</root>
Notice the appearing of empty default namespace xmlns="" on the child element(s). What actually needs to be done is to modify the namespace of every node or to create a new document with the desired default namespace and copy the contents, element and attribute names etc. of the old document to the new one. These can be done by recursively going through the original document. With Java DOM implementation this can be laborious, I've heard. One short cut might be to read the document with a namespace-unaware DOM and then add as attribute the new default namespace. Other solution is to change the namespace with an XSLT transformation, which seems quite suitable in this case, since you actually are already generating the output via XSLT transformation.
Use this XSLT stylesheet to add a new default namespace and the schema location to the root element. This stylesheet preserves old namespaces but adds all elements to new default namespace if they previously were in no-namespace.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- Template to add a default namespace to a document -->
<!-- Elements without a namespace are "moved" to default namespace -->
<!-- Elements with a namespace are copied as such -->
<!-- string for default namespace uri and schema location -->
<xsl:variable name="ns" select="'namespaceURL'"/>
<xsl:variable name="schemaLoc" select="'namespaceURL pathToMySchema.xsd'"/>
<!-- template for root element -->
<!-- adds default namespace and schema location -->
<xsl:template match="/*" priority="1">
<xsl:element name="{local-name()}" namespace="{$ns}">
<xsl:attribute name="xsi:schemaLocation"
namespace="http://www.w3.org/2001/XMLSchema-instance">
<xsl:value-of select="$schemaLoc"/>
</xsl:attribute>
<xsl:apply-templates select="#* | node()"/>
</xsl:element>
</xsl:template>
<!--template for elements without a namespace -->
<xsl:template match="*[namespace-uri() = '']">
<xsl:element name="{local-name()}" namespace="{$ns}">
<xsl:apply-templates select="#* | node()"/>
</xsl:element>
</xsl:template>
<!--template for elements with a namespace -->
<xsl:template match="*[not(namespace-uri() = '')]">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<!--template to copy attributes, text, PIs and comments -->
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Instead of creating the transformer with
Transformer trans = transfac.newTransformer();
(which creates and stylesheet that does an identy transformation), create an XSLT input source and give it as a parameter to newTransformer()
javax.xml.transform.Source xsltSource = new javax.xml.transform.stream.StreamSource(xsltFile);
Transformer trans = transFact.newTransformer(xsltSource);
where xsltFile is a File object pointing to that XSLT file.
Set the output properties as you wish and call transform() as in your sample code. The result should be what you desired, but I have not tested this in Java. The given XSLT file is tested for some trivial cases and there is a sample input and output at the end of this answer.
Some minor notes:
The original document object is not modified in this process. The new default namespace only appears in the output of the transform() method.
The namespace prefix for schema-instance namespace is usually xsi:, not xs: as in your example code (xs: is used in schema definitions (as well as xsd:)) .
Sample input and output for the XSLT stylesheet shown above
Input:
<root>
<child>text</child>
<child attribute="attr-value"/>
<?pi-target pi-content?>
<nsx:ns-child xmlns:nsx="ns1x">
<no-ns-child>text</no-ns-child>
<!-- comment -->
<nsx:ns-child nsx:ns-attribute="nsx-attr-value">text</nsx:ns-child>
</nsx:ns-child>
<defns-child xmlns="default-ns">
<def-child attr="val">text</def-child>
<child xmlns=""/>
</defns-child>
<child>text</child>
</root>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="namespaceURL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="namespaceURL pathToMySchema.xsd">
<child>text</child>
<child attribute="attr-value"/>
<?pi-target pi-content?>
<nsx:ns-child xmlns:nsx="ns1x">
<no-ns-child>text</no-ns-child>
<!-- comment -->
<nsx:ns-child nsx:ns-attribute="nsx-attr-value">text</nsx:ns-child>
</nsx:ns-child>
<defns-child xmlns="default-ns">
<def-child attr="val">text</def-child>
<child xmlns="namespaceURL"/>
</defns-child>
<child>text</child>
</root>
You can add the namespaces in the root when creating the document.
String NS_URL = "namespaceURL";
doc = builder.newDocument();
Element root = doc.createElementNS(NS_URL, "root");
root.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance",
"xs:schemaLocation", NS_URL + " pathToMySchema.xsd");
doc.appendChild(root);
Then for each element added to the doc instead of createElement() use createElementNS()
doc.createElementNS(NS_URL, name);
This results in what you were looking for.
<root
xmlns="namespaceURL"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="namespaceURL pathToMySchema.xsd"
>
Here's how to give a hint to the parser in order to solve your problem:
http://bytes.com/topic/java/answers/16892-xerces-how-perfrom-schema-validations-without-using-xsi-schemalocation
It goes like this:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLocation",
"http://www.example.com/Report.xsd");
Here is a validation example with some source code. It might help you.
http://www.ibm.com/developerworks/xml/library/x-tipvalschm/
(If all comes to worse, you can always search-and-replace. I know it is not the ideal solution, but the javax.xml.transform.OutputKeys doesn't seem to have a member related to the schemalocation attribute.)