What’s so bad about building XML with string concatenation?
You can end up with invalid XML, but you will not find out until you parse it again – and then it is too late. I learned this the hard way.
You can end up with invalid XML, but you will not find out until you parse it again – and then it is too late. I learned this the hard way.
I don’t use xmllint, but I think the reason your XPath isn’t working is because your doc.xml file is using a default namespace (http://purl.org/net/ulf/ns/0.4-02). From what I can see, you have 2 options. A. Use xmllint in shell mode and declare the namespace with a prefix. You can then use that prefix in your XPath. … Read more
This transformation: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:template match=”t”> <p> <xsl:apply-templates/> </p> </xsl:template> <xsl:template match=”text()” name=”insertBreaks”> <xsl:param name=”pText” select=”.”/> <xsl:choose> <xsl:when test=”not(contains($pText, ‘
’))”> <xsl:copy-of select=”$pText”/> </xsl:when> <xsl:otherwise> <xsl:value-of select=”substring-before($pText, ‘
’)”/> <br /> <xsl:call-template name=”insertBreaks”> <xsl:with-param name=”pText” select= “substring-after($pText, ‘
’)”/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> when applied on this XML document: <t>Line1 Line2 Line3 </t> … Read more
In an ideal world, you’d be able to validate using a Validator. Something like this: SchemaFactory schemaFactory = SchemaFactory .newInstance(XMLConstants.XML_DTD_NS_URI); Schema schema = schemaFactory.newSchema(new File( “xmlValidate.dtd”)); Validator validator = schema.newValidator(); validator.validate(new StreamSource(“xmlValidate.xml”)); Unfortunately, the Sun implementation (at least, as of Java 6) does not include support for creating a Schema instance from a DTD. You … Read more
You can try this way as well. I have tried and tested it myself. Step 1 : Please Download the java-json.jar Step 2: Add this to /libs folder of your project then add to build path. Step 3: Then use it as follows Imports to look for import org.json.JSONException; import org.json.JSONObject; import org.json.XML; Sample string … Read more
Stumbled across this question whilst having a very similar problem, I’d been running a query processing a 7.5MB XML file (~approx 10,000 nodes) for around 3.5~4 hours before finally giving up. However, after a little more research I found that having typed the XML using a schema and created an XML Index (I’d bulk inserted … Read more
The currently accepted answer will return incorrect paths. For example, the element Ele2 in the OP sample XML would return the path /Doc[1]/Ele2[2]. It should be /Doc[1]/Ele2[1]. Here’s a similar XSLT 1.0 template that returns the correct paths: <xsl:template name=”genPath”> <xsl:param name=”prevPath”/> <xsl:variable name=”currPath” select=”concat(“https://stackoverflow.com/”,name(),'[‘, count(preceding-sibling::*[name() = name(current())])+1,’]’,$prevPath)”/> <xsl:for-each select=”parent::*”> <xsl:call-template name=”genPath”> <xsl:with-param name=”prevPath” select=”$currPath”/> … Read more
AFAIK, you can’t create a File from an assets file because these are stored in the apk, that means there is no path to an assets folder. But, you can try to create that File using a buffer and the AssetManager (it provides access to an application’s raw asset files). Try to do something like: … Read more
From Sowmy Srinivasan’s Blog – Serializing internal types using XmlSerializer: Being able to serialize internal types is one of the common requests seen by the XmlSerializer team. It is a reasonable request from people shipping libraries. They do not want to make the XmlSerializer types public just for the sake of the serializer. I recently … Read more
2018 Update A lot has changed in the last 7 years. The best way to handle this type of layout these days is to use CardView which has built in support for rounded corners and many other newer UI features as well. Apply the cardCornerRadius property to set the corners to round. <android.support.v7.widget.CardView ……. app:cardCornerRadius=”16dp”> … Read more