Abdera parser: how to acess element with different namespaces - apache-abdera

Let's say I have an Atom entry like this:
<entry xmlns:custom="http://custom.xsd">
<title>test</title>
<custom:solution>42</custom:solution>
</entry>
If I load the entry into Apache Abdera, I get a nice org.apache.abdera.model.Entry instance. And I can now conveniently access all standard Atom elements with getters.
But how would I read the value 42 from the custom:solution element?

You can use something like:
for (Element element : (List<Element>)entry.getExtensions(" <UrI for custom namespace>")) {
System.out.println(element.getText());// gives you 42
}

Related

Get the values from the <xd:doc/>

I want to access the version information which I store in the
<xsl:stylesheet>
<xd:doc scope="stylesheet">
<xd:ul>
<xd:li>
<xd:i>Updates</xd:i>: <xd:ul>
<xd:li>20.11.2018, version: <xd:i>1.1.0</xd:i></xd:li>
<xd:li>08.03.2019, version: <xd:i>2.0.0</xd:i></xd:li>
<xd:li>11.03.2019, version: <xd:i>2.0.1</xd:i></xd:li>
</xd:ul>
</xd:li>
</xd:ul>
</xd:doc>
</xsl:stylesheet>
Normally the XPath of the #select is evaluated to the xml-file which is currently transforming. But how refer XPath to the (main) XSL-stylesheet?
Another option would be to use fn:doc(). But I want to place the version-writing-functionality in an external module, so there will be dynamic file names and I don't know how to get the xsl-file name
I use oXygen XML editor 20.1 where I define the transformation scenarios.
#MartinHonnen Thank you. I updated the code in the question. As you may see I store the version in the docs of the stylesheet.
The document('') / doc('') was what I needed. So I implemented the following:
I put the document-node of the main stylesheet in the variable which is placed in this stylesheet:
<xsl:variable name="currentStylesheet" select="doc('')"/>
then refer to it in the external module
<xsl:variable as="xs:string" name="versionXSLT" select="$currentStylesheet//xd:li[xd:i = 'Updates']/xd:ul/xd:li[last()]/xd:i/string()"/>
I also use it to get the name of the stylesheet:
<xsl:variable as="xs:string" name="currentStylesheetName" select="tokenize(document-uri($currentStylesheet), '/')[last()]"/>
Are there maybe better solutions?

How to pass a dynamic delimiter to csv marshalling in camel?

i want to pass a dynamic delimiter to the csv marshalling like below.
<marshal>
<csv delimiter="${header.FIELD_DELIMITER}"/>
</marshal>
when i try as above i am getting this exception:
Caused by: java.lang.IllegalArgumentException: Delimiter must have a length of one!
at org.apache.camel.model.dataformat.CsvDataFormat.configureDataFormat(CsvDataFormat.java:138)
at org.apache.camel.model.DataFormatDefinition.getDataFormat(DataFormatDefinition.java:88)
at org.apache.camel.model.DataFormatDefinition.getDataFormat(DataFormatDefinition.java:80)
at org.apache.camel.model.MarshalDefinition.createProcessor(MarshalDefinition.java:158)
at org.apache.camel.model.ProcessorDefinition.createProcessor(ProcessorDefinition.java:460)
at org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:429)
at org.apache.camel.model.TryDefinition.createProcessor(TryDefinition.java:73)
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:500)t
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:213)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:909)
... 19 more
Instead of doing this
<marshal>
<csv delimiter="${header.FIELD_DELIMITER}"/>
</marshal>
You need to do this:
<toD uri="dataformat:csv:marshal?delimiter=${header.FIELD_DELIMITER}"/>
This is dynamic routing and you will need to use this whenever you want to create URIs on runtime based on runtime values.
You cannot do that with marshal. However you can use the dataformat endpoint and the dynamic to pattern. See more details at:
http://camel.apache.org/dataformat-component.html
http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html

How to use MDS customization to add JSTL functions tag library?

I added the JSTL functions tag library into the folderViewer.jsff view in the WebCenter Portal 11.1.1.6.0 folderViewer taskflow (oracle.webcenter.doclib.view.jsf.taskflows.folderViewer), so that I can perform string operations prior to rendering the view.
I added it using the following mds:modify block in the folderViewer.jsff.xml MDS customization file:
<mds:modify element="(xmlns(jsp=http://java.sun.com/JSP/Page))/jsp:root">
<mds:attribute name="version" value="2.1"/>
<mds:attribute name="xmlns:fn" value="http://java.sun.com/jsp/jstl/functions"/>
</mds:modify>
This allows me to use the JSTL functions in EL statements, such as: startFolderPath=#{fn:replace(fn:substringAfter(item.url,'path'),'%20','%2520')}.
However, there seems to be an unintended side-effect of this in the folderViewer task flow. When there are over 50 subfolders in a folder, scrolling past the 50th subfolder and trying to navigate to one of the subfolders (i.e. navigating to subfolder #51) results in a WebCenter error page being displayed and the following error in the logs:
<Oct 28, 2013 3:10:54 PM CDT> <Error> <oracle.webcenter.webcenterapp.internal.view.webapp> <BEA-000000> <
oracle.mds.exception.MDSRuntimeException: invalid namespace http://java.sun.com/JSP/Page for prefix xmlns
invalid namespace http://java.sun.com/JSP/Page for prefix xmlns
at oracle.mds.core.MOTxnState.getDocument(MOTxnState.java:266)
at oracle.mds.core.UpdateableMOContent.getDocument(UpdateableMOContent.java:561)
at oracle.mds.core.MetadataObject.getDocument(MetadataObject.java:449)
at oracle.mds.core.MetadataObject.getDocument(MetadataObject.java:396)
...
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
>
<Oct 28, 2013 3:10:54 PM CDT> <Error> <oracle.webcenter.webcenterapp> <BEA-000000> <Internal Error (WCS#2013.10.28.15.10.54)>
If I remove the MDS customization to folderViewer.jsff.xml that adds the JSTL Functions tag library, this issue does not exist.
Does anyone know of a different way to add a new tag library via MDS customization?
Thanks,
Joe
It seems like its trying to give prefix xmlns instead of JSP
I'm just wonder if you changed the above code to the following, what will happen
<mds:modify element="jsp:root">
<mds:attribute name="version" value="2.1"/>
<mds:attribute name="xmlns:jsp" value="http://java.sun.com/JSP/Page"/>
<mds:attribute name="xmlns:fn" value="http://java.sun.com/jsp/jstl/functions"/>
</mds:modify>

extjs: write an xml without root using xmlwriter

when sending a response to a server using xmlwriter, the root tag will always be added to the request:
If I want to post an item:
<book>
<id></id>
<title></title>
<publisher></publisher>
</book>
the actual generated xml is:
<xmlData>
<book>
<id></id>
<title></title>
<publisher></publisher>
</book>
</xmlData>
I can make sure that only one record will be posted: one book for each request
how can I remove the xmlData element? that is to say, make book tag to be the root element
the extjs document says:
Ext.data.writer.Xml
documentRoot : String
The name of the root element of the document. Defaults to 'xmlData'. If there is more than 1 record and the root is not specified, the default document root will still be used to ensure a valid XML document is created.
My understanding is that if there is only one record, the default document root will not be used. Am I right? But acturaly, the root element 'xmlData' is still added even if there is only one record.
Thanks
The Ext.data.writer.Xml class has two configuration properties related to the root element: documentRoot and defaultDocumentRoot. As you noted, the documentation says:
If there is more than 1 record and the root is not specified, the default document root will still be used to ensure a valid XML document is created.
In other words, if documentRoot is null, but more than one record is written, the value of defaultDocumentRoot will be used as the root element. In your case, there is only one record, but documentRoot is not null, as its default value is "xmlData".
To omit the root element for single records, then, you need to explicitly set documentRoot to null:
new Ext.data.writer.Xml({ documentRoot: null });

Windows 7 Mobile Silverlight : Linq to XML issue

I have a XML Document:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>blahblah</title>
<subtitle>blahblah.</subtitle>
<link href="blahblah"/>
<link href="blahblah"/>
<updated>blahblah</updated>
<author>
<name>blahblah</name>
</author>
<id>blahblah</id>
<entry>
<title>blahblah</title>
<content type="html"><![CDATA[“some text.”]]></content>
</entry>
</feed>
I want to get the entry nodes content information, here's my code:
var xmlTreeVal = XDocument.Load("myxml.xml");
var returnVal = from item in xmlTreeVerse.Descendants("feed").Elements("entry")
select new VerseModel
{
Verse = item.Element("content").Value
};
The xml document is loading fine (as i could tell via debugging), but it keeps throwing a 'No sequential items found' error. How do I find the "content" nodes info?
Whenever your XML has a namespace (indicated by the xmlns attribute) you must reference the elements by also referencing their namespace. This is done by concatenating the namespace to the element name.
Also, you used xmlTreeVal but then reference xmlTreeVerse - it's probably not the problem but it's an inconsistency in the code you presented.
Try this:
var ns = xmlTreeVerse.Root.GetDefaultNamespace();
var returnVal = from item in xmlTreeVerse.Descendants(ns + "feed").Elements(ns + "entry")
select new
{
Verse = item.Element(ns + "content").Value
};

Resources