I am currently trying to reference a node in an XML document using the java library org.apache.xmlbeans.XmlCursor with the command XMLCursor.selectPath(“XPath Call goes here”).
I am able to get this command working for finding an element using:
picCur.selectPath("declare namespace p='http://schemas.openxmlformats.org/drawingml/2006/main'; .//p:blip");
However now I wish to select an element with a specific attribute. This would usually be done using the same command with .//p:blip[#embed=”attribute value” however the attribute has a different namespace to the element and I am struggling to find a way to declare both namespaces before executing the Xpath command. This is the command that I have been trying to use:
picCur.selectPath("declare namespace p='http://schemas.openxmlformats.org/drawingml/2006/main' ” +
"declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' " +
".//p:blip[#r:embed=' attribute value ']");
Below is the xml code, thank you in advanced for your help.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
<p:cSld>
<p:spTree>
<p:nvGrpSpPr>
<p:cNvPr id="1" name="" />
<p:cNvGrpSpPr/>
<p:nvPr/></p:nvGrpSpPr>
<p:grpSpPr>
<a:xfrm><a:off x="0" y="0" /><a:ext cx="0" cy="0" /><a:chOff x="0" y="0" /><a:chExt cx="0" cy="0" /></a:xfrm>
</p:grpSpPr>
<p:sp>
<p:nvSpPr>
<p:cNvPr id="2" name="Title 1" />
<p:cNvSpPr><a:spLocks noGrp="1" />
</p:cNvSpPr>
<p:nvPr>
<p:ph type="title" /></p:nvPr>
</p:nvSpPr>
<p:spPr/>
<p:txBody><a:bodyPr/><a:lstStyle/>
<a:p>
<a:r><a:rPr lang="en-GB" dirty="0" smtClean="0" />
<a:t>Worlds Cutest Dragon</a:t>
</a:r><a:endParaRPr lang="en-GB" dirty="0" /></a:p>
</p:txBody>
</p:sp>
<p:pic>
<p:nvPicPr>
<p:cNvPr id="4" name="myDragon" />
<p:cNvPicPr><a:picLocks noGrp="1" noChangeAspect="1" />
</p:cNvPicPr>
<p:nvPr>
<p:ph idx="1" /></p:nvPr>
</p:nvPicPr>
<p:blipFill>
<a:blip r:embed="rId2">
<a:extLst>
<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}"><a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0" />
</a:ext>
</a:extLst>
</a:blip>
<a:stretch><a:fillRect/></a:stretch>
</p:blipFill>
<p:spPr>
<a:xfrm><a:off x="3643312" y="2634456" /><a:ext cx="1857375" cy="2457450" /></a:xfrm>
</p:spPr>
</p:pic>
</p:spTree>
<p:extLst>
<p:ext uri="{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}">
<p14:creationId xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="2185825445" />
</p:ext>
</p:extLst>
</p:cSld>
<p:clrMapOvr><a:masterClrMapping/>
</p:clrMapOvr>
</p:sld>
Have you tried to declare the first namespace and then the other?
picCur.selectPath("
declare namespace p='http://schemas.openxmlformats.org/drawingml/2006/main';
declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships';
.//p:blip[#r:embed='value']
");
Please try it by adding saxonb ,saxon-dom, xbean jars to server..
Related
While using Apache FOP 2.2 from my Java application to print Hindi strings in PDF by using mangal.ttf, some Hindi characters are not displayed correctly.
I am Using JDK 1.8 and spring MVC.
I tried lohit.ttf, devanagari.ttf, aparajita.ttf and kokila.ttf but all have the same issue.
case 1:
When fop-conf.xml is set as below:
<font kerning="yes" embed-url="classpath:/mangal.ttf" >
<font-triplet name="Mangal" style="normal" weight="normal"></font-triplet>
</font>
Result: से is shown like this स े, as shown in this screenshot
case 2:
When fop-conf.xml is set as below:
<font kerning="yes" metrics-url="classpath:/mangal.xml" embed-url="classpath:/mangal.ttf" >
<font-triplet name="Mangal" style="normal" weight="normal"></font-triplet>
</font>
Result: problem listed in case 1 is resolved but I am facing another issue attached as shown in the following screenshot
You can see the expected output at the link https://www.fonts.com/font/microsoft-corporation/aparajita) using this sample text:
से and ग्रामीण should be printed in pdf
Other things I tried:
I tried PDFOne to generate the PDF. Yet the same issue. Windows however seems to show it correctly.
configuring complex-script: <fop version="1.0"> <complex-scripts disabled="true"/> ... </fop>
using the script attribute: <fo:block font-family="ARIALUNI" script="dev2" > देवी ग्रामीण</fo:block>
Is there any configuration setting in FOP that I am missing?
Shorter, general answer:
If the font is configured but the output is not correct, the problem could be FOP incorrectly determining which script mode to use.
Solution: explicitly set the script property in the FO file, using either a standard or an extended script code.
Note that Indic scripts have both a standard code and an extended one (for example deva and dev2 for Devanagari) and the resulting output is different, so you may need to try them both and choose the appropriate one.
Longer answer:
I don't have the fonts you mention available, so I tested using the Amiko Google Open Font.
More importantly, I know nothing about devanagari script, so I really cannot say whether the output is right or wrong, I can only compare it with your images.
This is the complete input file I used, with the sentence copied from your question:
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simpleA4">
<fo:flow flow-name="xsl-region-body">
<fo:block font-family="Amiko" script="deva">deva: से and ग्रामीण should be printed in pdf</fo:block>
<fo:block font-family="Amiko" script="dev2">dev2: से and ग्रामीण should be printed in pdf</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Here is a minimal configuration:
<?xml version="1.0"?>
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<fonts>
<font kerning="yes" embed-url="Amiko/Amiko-Regular.ttf">
<font-triplet name="Amiko" style="normal" weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
which produces this output:
If I understand correctly, the output you are trying to achieve is the one with script="deva".
Note that the metrics-url attribute in your configuration is not needed.
Moreover, putting <complex-scripts disabled="true"/> in your configuration has the effect of disabling the "complex script" support, so I expect this to produce the wrong output.
This configuration
<?xml version="1.0"?>
<fop version="1.0">
<complex-scripts disabled="true"/>
<renderers>
<renderer mime="application/pdf">
<fonts>
<font kerning="yes" embed-url="Amiko/Amiko-Regular.ttf">
<font-triplet name="Amiko" style="normal" weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
produces the following output:
This might help others who are struggling to get Indic language support in Apache FOP. I tried to render Hindi with Amiko font and it works like a charm.
I wanted to see if other Indian languages are supported in the same way, after a bit of struggle I could see Kannada can also be rendered .
<font kerning="yes" embed-url="Benne-Regular.ttf">
<font-triplet name="Benne" style="normal" weight="normal"/>
</font>
But its mandatory to mention the script in the XSL .
<fo:block font-family="Benne" script="knda" font-size="16pt"> ಕನ್ನಡ
ನನಗೆ ಇನ್ನೂ ಒಂದು ಪ್ರಶ್ನೆ ಇದೆ.</fo:block>
I saw some xml parsing in java but I really don't know how I can apply it to my code.
Here is my xml file:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="https://adomain.com">
<id>https://sharepoint.mydomain/aFile)</id>
<category term="SP.File" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<title />
<updated>2015-05-18T07:13:18Z</updated>
<author>
Bla Bla<name />
</author>
<content type="application/xml">
<m:properties>
<d:CheckInComment />
<d:CheckOutType m:type="Edm.Int32">2</d:CheckOutType>
<d:ContentTag>{63FD2CFA-D223-405B-86B3-D59B34ECEBBE},3,1</d:ContentTag>
<d:CustomizedPageStatus m:type="Edm.Int32">0</d:CustomizedPageStatus>
<d:ETag>"{63FD2CFA-D223-405B-86B3-D59B34ECEBBE},3"</d:ETag>
<d:Exists m:type="Edm.Boolean">true</d:Exists>
<d:Length m:type="Edm.Int64">638367</d:Length>
<d:Level m:type="Edm.Byte">2</d:Level>
<d:MajorVersion m:type="Edm.Int32">0</d:MajorVersion>
<d:MinorVersion m:type="Edm.Int32">1</d:MinorVersion>
<d:Name>aName.pdf</d:Name>
<d:ServerRelativeUrl>/mydomain.com/afile</d:ServerRelativeUrl>
<d:TimeCreated m:type="Edm.DateTime">2014-09-03T15:30:22Z</d:TimeCreated>
<d:TimeLastModified m:type="Edm.DateTime">2014-09-03T15:30:25Z</d:TimeLastModified>
<d:Title />
<d:UIVersion m:type="Edm.Int32">1</d:UIVersion>
<d:UIVersionLabel>0.1</d:UIVersionLabel>
</m:properties>
</content>
</entry>
I am trying to get the metadata of a file from SharePoint which is displayed in xml format.
How can I get the data which is inside the content and also the title and the author like this:
Author BlaBla
Title Bla
Type application/xml
TimeLastModified xx/xx/xxxx
The easiest way to parse XML files is the DOM parser. You can find the documentation here and a few tutorials here and here.
Also, a related question in stackoverflow here.
You can use Jaxb, now a days it is used for parsing purpose very effectively, Converting XML to JAVA called UnMarshalling http://www.javatpoint.com/jaxb-tutorial
I have a java program installed on my computer that creates Forms and can later print it. I want to do something similar with my program! In the source folders of this program, I found folders for the specific forms. Each folder containes a image for e.g named Payment.png and a xml file is structured like this:
<?xml version="1.0" encoding="windows-1250" standalone="no"?>
<form xmlns:xinclude="http://www.w3.org/2001/XInclude" blankodruck="true" filename="Payment.png" saveAndPrintButtonEnabled="true" scale="1.0" title="Payment" window_height="725" window_width="860" paper="A5" orientation="landscape">
<printscale sx="0.432" sy="0.434"/>
<printoffset x="0" y="13"/>
<model class="de.hans.client.app.form.payment.PaymentModel" />
<printform filename="Payment.png" pngscaleX="1" pngscaleY="1"/>
<offset x="-20" y="15" scaleX="0.72" scaleY="0.7" printOffsetX="4" printOffsetY="3" printScaleX="2.34" printScaleY="2.33">
<xinclude:include href="../Header.xml"/>
</offset>
<checkbox height="33" name="Paydaten_ChB" width="35" x="862" y="74" printOffsetX="0" printOffsetY="0"/>
<checkbox columns="90" height="35" ...
<textfield columns="1" height="36" name="quartal" width="35" x="1235" y="72" printOffsetX="0" printOffsetY="0"/>
<radiobutton group="Gender" height="36" name="User_gender" tooltip="men" width="33" x="1253" y="130" printOffsetX="0" printOffsetY="0"/>
It has even a barcode-field:
<barcode length="886" type="3" px="430" py="180" pages="1">
<invisible name="date"/>
<invisible name="titel"/>
Can somebody guess how this printable swings are created in the program? Thanks
I'm interested to parse an XML that contains variables (which are defined by me inside the XML).
Here's an example of the XML files:
<parameters>
<parameter name="parent-id" value="1" />
<parameter name="child-id" value="1" />
</parameters>
<Parents>
<Parent id="$(parent-id)">
<Children>
<Child id="$(child-id)">
</Child>
</Children>
</Parent>
</Parents>
Is there a utility or some standard way to do so in Java? (using JAXB possibly)
Or should I implement this "mini" parsing mechanism by myself?
(A mechanism that identifies the variables and plants them inside the XML, and only later calls JAXB flows)
Thanks a lot in advance!
Use an XSLT transformation to convert your XML into an XSLT stylesheet and then execute the XSLT stylesheet. It's simple enough to convert
<parameters>
<parameter name="parent-id" value="1" />
<parameter name="child-id" value="1" />
</parameters>
into
<xsl:param name="parent-id" select="1" />
<xsl:param name="child-id" select="1" />
and
<Parent id="$(parent-id)">
into
<Parent id="{$parent-id}">
and to add a wrapper xsl:stylesheet and xsl:template element, and then you're done.
As I understood it before taking this job, XML Uses a series of key-value pairs that up till today seemed fairly straight forward with how I was using it. Basically I need to parse an XML document like this in Android:
<MailingAddress Caption="Mailing Address" PropertyType="CRM.Address" FieldType="4" DisplayType="0" ValueType="0" IsRequired="False">
<CRM.Address>
<Street Caption="Street" PropertyType="System.String" FieldType="1" DisplayType="1" ValueType="1" MaxDataLength="400" IsRequired="False" />
<City Caption="City" PropertyType="System.String" FieldType="1" DisplayType="1" ValueType="1" MaxDataLength="400" IsRequired="False" />
<State Caption="State" PropertyType="System.String" FieldType="1" DisplayType="1" ValueType="1" MaxDataLength="200" IsRequired="False" />
<PostalCode Caption="Postal Code" PropertyType="System.String" FieldType="1" DisplayType="1" ValueType="1" MaxDataLength="100" IsRequired="False" />
<Country Caption="Country" PropertyType="System.String" FieldType="1" DisplayType="1" ValueType="1" MaxDataLength="200" IsRequired="False" />
</CRM.Address>
Does anyone know how I might go about parsing this or know of a parser that would be useful to me? Am I going to have to write my own parser?
This looks like well formed xml , so have a schema, generate POJO using xsd to java command , and de-serilize then we should have values in xml as POJO thus we can do whatever we want from java pojo