I am trying to embed images in xml document and save the document as a single document and be able to distribute the file just like microsoft word where both the text and images are saved in single docx file.
How is it done in Microsoft word. Do they use base64 encoding ?
It is quite hard to do it by hand and would look something like that:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:r>
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="5943600" cy="3717290"/>
<wp:docPr id="1" name="Picture 0" descr="vlcsnap-325726.png"/>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:nvPicPr>
<pic:cNvPr id="0" name="myImage.png"/>
<pic:cNvPicPr/>
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed="rId4"/>
<a:stretch>
<a:fillRect/>
</a:stretch>
</pic:blipFill>
<pic:spPr>
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="5943600" cy="3717290"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
</w:r>
</w:p>
</w:body>
</w:document>
You don't want to do it that way. I would recommend to use an external library like OpenXML SDK 2.0 (by Microsoft) or OpenXML4J (especially for Java). They will make your life way easier
Related
I am building a component which allows the user to add a multi field. When the multifield is added to the dialog, the user is presented with two text boxes. When the user adds information to the text boxes, and clicks 'OK'. When the dialog closes, no information is stored/saved.
Can anyone point out where I've gone wrong?
See the dialog code below:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Dialog"
xtype="dialog">
<items
jcr:primaryType="nt:unstructured"
xtype="panel">
<items jcr:primaryType="cq:WidgetCollection">
<heading
jcr:primaryType="nt:unstructured"
allowBlank="true"
disabled="false"
fieldLabel="Heading (optional)"
grow="false"
hideLabel="false"
name="./headingTitle"
readOnly="false"
selectOnFocus="false"
validateOnBlur="true"
xtype="textfield"/>
<message
jcr:primaryType="nt:unstructured"
fieldLabel="Message (optional)"
name="./message"
validateOnBlur="true"
xtype="textfield"/>
<link-list
jcr:primaryType="cq:Widget"
fieldLabel="Tabs titles and binding"
border="{Boolean}false"
name="./link-list"
width="1000"
xtype="multifield">
<fieldConfig
jcr:primaryType="cq:Widget"
path="/apps/group/components/nab-broker-tabs/dialog/items/items/link-list/fieldConfig/items.infinity.json"
xtype="cq.compositefield">
<items jcr:primaryType="cq:WidgetCollection">
<linkText
jcr:primaryType="cq:Widget"
fieldLabel="Titles"
name="linkText"
width="180"
xtype="textfield"/>
<linkBinding
jcr:primaryType="cq:Widget"
fieldLabel="binding ID"
name="linkBinding"
width="180"
xtype="textfield"/>
</items>
</fieldConfig>
</link-list>
</items>
</items>
</jcr:root>
Since multiple values are to be stored, you should be using a custom xtype to store multifield values.
refer: http://helpx.adobe.com/experience-manager/using/creating-custom-xtype.html
In case of complex multifield components, I would suggest you to use Multi Field Panel from ACS AEM Commons.
It will do the job for you.
I am using FOP to tranform xml to pdf, and I need to use Chinese characters.I did do something to use Chinese font,but it seems don't work at all.
I create the font xml file.
and registered in the fop.xconf
<font metrics-url="/home/zhufree/Tools/fop-2.1/conf/simkai.xml" kerning="yes" embed-url="/home/zhufree/Tools/fop-2.1/conf/kaiti.ttf">
<font-triplet name="simkai" style="normal" weight="normal" />
<font-triplet name="simkai" style="normal" weight="bold" />
<font-triplet name="simkai" style="italic" weight="normal" />
<font-triplet name="simkai" style="italic" weight="bold" />
</font>
the font xml file and font ttf file are in the same directory with fop.xconf,when I try to transform,it still show me cant find the font.
What should I do to show the Chinese character?
Update:
I solved the problem by using specific configuration file in java code, and it worked well.Thanks.
I am currently developing a system that uses the following format of XML files to for configuration purposes:
<?xml version="1.0" encoding="utf-8"?>
<Branch>
<Department>
<Door id="1" enabled="true"/>
<Door id="2" enabled="true"/>
</Department>
<Department>
<Door id="3" enabled="true"/>
<Door id="4" enabled="false"/>
</Department>
<Department>
....
</Branch>
Do you know how could I parse this XML file?
I have been looking for other answers but I could only get it to work till the Department node. It isn't interpreting the Door node level.
Greetings fellow programmers!
I am having a major problem while unmarshalling xml to an object. I need to a create a reference to an object. How can I accomplish it? I've tried to use XSL transformation but due to cycle occurence this wasnt a right approach. I am 100% sure there's an easy way out.. Here's my XML:
<report>
<subject>
<subjectId>1</subjectId>
<name>John</name>
<surname>Doe</surname>
</subject>
<subject>
<subjectId>2</subjectId>
<name>Frank</name>
<surname>Timothy</surname>
</subject>
<individual>
<individualId>10</individualId>
<name>Isaac</name>
<surname>Newton</surname>
<co-worker>
<subject>
<subjectId>1</subjectId>
<inXml>true</inXml>
</subject>
<subject>
<subjectId>2</subjectId>
<inXml>true</inXml>
</subject>
</co-worker>
</individual>
<owner>
<subject>
<subjectId>2</subjectId>
<inXml>true</inXml>
</subject>
<share>100</share>
</owner>
</report>
I need to create reference of "subject" or "individual" with inXml=true. This flag tells me wether we have got entity with that ID in the XML.
Thank you very much for your help :)
You can use #XmlID/#XmlIDREF to map key based relationships in your XML document.
Example
http://blog.bdoughan.com/2010/10/jaxb-and-shared-references-xmlid-and.html
I have an XML document as follows:
<?xml version="1.0" encoding="UTF-8"?>
<decision>
<question id="0">
<questionText>What type is your OS?</questionText>
<answer id="0">
<answerText>windows</answerText>
</answer>
<answer id="1">
<answerText>linux</answerText>
</answer>
<answer id="2">
<answerText>mac</answerText>
</answer>
</question>
<question id="1">
<questionText>What are you looking for?</questionText>
<answer id="0">
<answerText>table</answerText>
<question id="0">
<questionText>Which color table you want?</questionText>
<answer id="0">
<answerText>green</answerText>
</answer>
<answer id="1">
<answerText>black</answerText>
</answer>
<answer id="2">
<answerText>pink</answerText>
</answer>
</question>
</answer>
<answer id="1">
<answerText>chair</answerText>
</answer>
<answer id="2">
<answerText>bed</answerText>
</answer>
<answer id="3">
<answerText>cloth</answerText>
</answer>
</question>
Now I want to parse the above XML using jdom in Java. It kind of recursive and important thing to note is a Question can't be a direct child of Question and same applies for Answer.
Article
In the light of previous related questions, I'd like to repeat and stress the advice of others (like JB Nizet commented on this question):
Learn Java, learn XML, pick the tools and API's you need for your project and learn to use those too. If at one point you get into trouble, everybody here will be happy to help you out debugging your code.
I'm aware that this may seem harsh but it gets to the point where your program gets built by StackOverflow users and not yourself.
That being said, the link at the top of this answer leads to a tutorial on using JDOM to traverse your XML.
Use Element.getChildren(String) to get all of the question tags and loop through that List - calling getChildren(String) to get all of the answers, or getChild(String) if there can be only one child element.
first that you need use is XSD to validate the XML.