xsl loading image to get metadata - java

i would like to load an image to get the metadata. my code is like this :
the value of "url" is like this : "http:\localhost:8080\mypics\pic1.jpg"
<xsl:call-template name="mypic">
<xsl:with-param name="metadata" select="document($url)/metadata"/>
</xsl:call-template>
i get this exception : ID systÞme inconnu; Ligne #47; Colonne #38; Unable to load the requested document : C:\http:\localhost:8080\mypics\pic1.jpg (the specific path was not found)
Thanks for help.

The value of $url should be
http://localhost:8080/mypics/pic1.jpg
Update
According to this documentation you need to specify an URI and the resource at that URI has to be of xml type. I strongly doubt, that you can handle images with this expression. The document() function is used to access (xml-)nodes in external documents.
I guess, the backslashes made the processor believe the string was pointing to a file resource, relative to C:\.

i would like to load an image to get the metadata. my code is like
this : the value of "url" is like this :
"http:\localhost:8080\mypics\pic1.jpg"
In XSLT you cant load a file unless it contains a well-formed XML document, or just text (not binary).
In an XSLT transformation only XML documents (with the document() function) or text files (with the XSLT 2.0 unparsed-text()) function can be loaded.

I assume that there is no native XSLT way to do this as I guess Dimitrie would have shown us one if existed.
The alternative is to drop out to Java. Write your own extension function in Java and call it from your XSLT. This link shows how this can be done:
http://www.redstream.nl/2011/03/29/xslt-2-0-and-java-extensions/

Related

Using JAVA, how can I parse .cshtml file and add parameters for the existing C# code in that file

I have some .CSHTML files that were incorrectly generated by a tool. I would like to modify the C# code in them to append additional parameters and remove incorrect parameters from method calls.
I've used JSoup to parse the HTML and JSP files. I am able to add or remove attribute in the HTML and JSP files via JSoup DOM iteration.
But in the .CSHTML files contains C# code (I'm new to C#) and couldn't get control over the code. Hence I am not able to append parameters for that C# code using JSoup library. For example,
<td>
#Html.Label(Resource.Get("Label_Name"), new Dictionary<string,object>{{ "Class","label"},{ "name","Name"},{ "id","Name"}})
</td>
<td>
#Html.TextBoxFor(m=> m.TextBox1,new Dictionary<string,object>{{ "Class","txtfield controlWidth"},{ "name","TextBox1"},{ "id","TextBox1"}})
</td>
As above "#Html.xxxx" codes are treated as value for the 'tr' tag in Jsoup DOM iteration. I could only think on adding if..else logic to add or remove parameters as snippet given below. I don't know what is the standard way of parsing such .cshtml file.
if(str.contains("#Html.")) {
ctrlType=str.substring(str.indexOf('.')+1,str.indexOf('('));
if(ctrlType.equalsIgnorecase("Label")) {
// logic to add parameters.
}
}
Using Java, is there way to parse the .cshtml file and add or remove parameters for C# code ? Can you please suggest to solve the problem with open standard API?

Jasper Reports Parse XML column-blob

I am using postgresql as database. In db i have one column which contains xml with language codes. I want to parse that xml and get value trough the report language.
select o.name,o.price from bookdefinations o This o.name contains that xml value:
<?xml version="1.0" encoding="UTF-8"?>
<values>
<en-us>en value</en-us>
<es>es value</es>
<ru>ru value</ru>
<tr>tr value</tr>
</values>
Can i parse this with jasper's expressions or can i parse while selecting from db (i dont have any idea how to get report language in select query and parse xml in select)
There is a xmldatasource for jasperreport, you can do a subreport and send the blob to that subreport as an xmldatasource, then you can parse the xml in the subreport and show the content, I'm not sure if you want to show the values or the entire xml, if it is a report I guess you should show the values in a pretty way I mean not as xml, check this link
http://jasperreports.sourceforge.net/sample.reference/xmldatasource/
You could do this directly in postgresql during the select.
PostgreSql has an XML Type and various XML functions.
If you take a look at those functions, you'll see the xpath function which can be used to extract data from XML types during a select statement.
For a reference to xPath, take a look at the tutorial from W3Schools.

In XSLT, how do I get the filepath of the xml file of a certain element if that xml file was included with xinclude?

I have these XML files:
master.xml (which uses XInclude to include child1.xml and child2.xml)
child1.xml
child2.xml
Both child1.xml and child2.xml contain a <section> element with some text.
In the XSLT transformation, I 'd want to add the name of the file the <section> element came from, so I get something like:
<section srcFile="child1.xml">Text from child 1.</section>
<section srcFile="child2.xml">Text from child 2.</section>
How do I retrieve the values child1.xml and child2.xml?
Unless you turn off that feature, all XInclude processors should add an #xml:base attribute
with the URL of the included file. So you don't have to do anything, it should already be:
<section xml:base="child1.xml">Text from child 1.</section>
<section xml:base="child2.xml">Text from child 2.</section>
( If you want, you can use XSLT to transform the #xml:base attr into #srcFile. )
I'm 99% sure that once xi:include has been processed, you have a single document (and single infoset) that won't let you determine which URL any given part of the document came from.
I think you will need to place that information directly in the individual included files. Having said that, you can still give document-uri a try, but I think all nodes will return the same URI.

Talend tExtractXMLField

I have this job in Talend that is supposed to retrieve a field and loop through it.
My big problem is that the code is looping through the XML fields but it's returning null.
Here is a sample of the XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<empresas>
<empresa>
<imoveis>
<imovel>
[-- some fields -- ]
<fotos>
<nome id="" order="">photo1</nome>
<nome id="" order=""></nome>
<nome id="" order=""></nome>
<nome id="" order=""></nome>
</fotos>
</imovel>
[ -- other entries here -- ]
</imoveis>
</empresa>
</empresas>
Now using the tExtractXMLField component I am trying to get the "fotos" element.
Here is what I have in the component:
I have tried to change the XPath query and the XPath loop query but the result is either I don't loop through the field or I get the null in the value field in the tMap.
Here is an image of the job:
You can see that I have retrieved 4 items from the XML but what I get is null in the "nome" field. There must be something wrong with the XPath but I can't seem to find the problem :(
Hope someone can help me out. Thanks
Notes: I am using talendv4.1.2 on ubuntu 10.10 64bit
If you want to loop on <nome> nodes your Loop XPath Query has to be
"/empresas/empresa/imoveis/imovel/fotos/nome"
and foto_nome XPath Query something like
"text()"
Take care: I also corrected an error in your XML that could bring issues (</imoveis> missing the "s").
There are two ways to go about it. One way is to use directly XMLinput and the instructions that bluish mentioned.
The other way is to continue on the path that you chose. In the XMLinput, make sure that your Loop XPath query is set to "/empresas/empresa/imoveis/imovel/fotos" and that you pass through the fotos element with the Get Nodes option checked. The XPath Query of your fotos element should be "../fotos" or ".".
Your extractXMLField component looks to be well configured.
Also, I don't know what tSetGlobalVar does in your design, but make sure it doesn't affect the fotos element that you're trying to pass through.
I have made a test job, this will help you definitely. If I'm not wrong you want to get all the "nome" under the "fotos" tag.
Try to change your loop xpath to the top level in the file, "empresas". Sometimes that works for me, also I have seem the "?xml version="1.0" encoding="ISO-8859-1"?" tag cause problems before, you could try to remove that.
Also make sure that the encoding is set correctly in the tFileInputXML.
I think you are confusing reading XML and extracting XML from XML.
Reading XML:
If the part of XML you have provided is the file readed by you tFileInputXML you don't need tExtractXMLField, just configure the tFileInputXML as this:
set the xpath loop to the <nome> elements, like this "//nome"
add 3 columns in the tFileInputXML component id, order and content
get content column with xpath query "."
get id value with xpath query "#id"
get order value with xpath query "#order"
Extracting XML from XML:
That is the goal of the tExtractXMLField component:
It allows to parse XML data contained in a database column or another XML document as if it was itself a data flow.
To put it in a nutshell, tExtractXMLField create a flow of data from a column record containing XML.
It is very useful when parsing soap query result: server reply is usually provided as xml, like this one:
<arg2>
<![CDATA[
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<exportInscriptionEnLigneType>
<date>2015-04-10</date>
<nbDossiers>2</nbDossiers>
<reference>20150410100</reference>
<listeDossiers>
<dossier>
<numOrdre>1</numOrdre>
<identifiantDossier>AAAAA</identifiantDossier>
</dossier>
<dossier>
<numOrdre>2</numOrdre>
<identifiantDossier>BBBBB</identifiantDossier>
</dossier>
</listeDossiers>
</exportInscriptionEnLigneType>
]]>
</arg2>
In XML above, arg2>element contains an XML document that you may need to parse.
tExtractXMLField has been created for this purpose.
I've written a tutorial on how to achieve this work, please have a look here "how to extract xml from xml". It is in french but screenshots may help understanding the few comments provided.
Hope it will help.
Best regards,

how to get the value of attribute processing by STAX using java language?

i want to get the value of attribute of xml file without knowing it's index, since attributes are repeated in more than one element in the xml file.
here is my xml file
<fields>
<form name="userAdditionFrom">
</form>
</fields>
and here is the procssing file
case XMLEvent.ATTRIBUTE:
//how can i know the index of attribute?
String attName = xmlReader.getAttributeValue(?????);
break;
thanx in advance.
Alaa
If it is XMLStreamReader then getAttributeValue(int index) and getAttributeValue(String namespaceURI, String localName) can be used to get attribute value.
From your question it look like you are using mix of Event and Cursor API. I have appended Using StAX link for your reference that gives idea how to use both.
Resources:
XMLStreamReader getAttributeValue(String, String) JavaDoc Entry
Using StAX

Categories

Resources