Using XSLT to copy all nodes in XML, with support for special cases

<?xml version=”1.0″?> <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <!–Identity template, provides default behavior that copies all content into the output –> <xsl:template match=”@*|node()”> <xsl:copy> <xsl:apply-templates select=”@*|node()”/> </xsl:copy> </xsl:template> <!–More specific template for Node766 that provides custom behavior –> <xsl:template match=”Node766″> <xsl:copy> <xsl:apply-templates select=”@*|node()”/> <!–Do something special for Node766, like add a certain string–> <xsl:text> add some text </xsl:text> … Read more

Is there an XML schema extension for Visual Studio Code?

The XML extension, by Red Hat, is now available in the Marketplace. It supports, among other things, XSD and DTD validation, autocompletion from XSD, documentation on hover, tag autoclose, formatting… It’s based on LemMinX, a Java-based language server. As of vscode-xml 0.15.0, Java is no longer required to run it (a native binary will be … Read more

Maven resource filtering for single file

I don’t know why Gabor’s solution did not work, but I managed to solve this way: Firstly I removed nonFilteredFileExtension tag: <nonFilteredFileExtension>xml</nonFilteredFileExtension> Then modified my resources this way: <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/myxml.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <includes> <include>**/*.xml</include> </includes> </resource> Now my single xml file is filtered and other is leaved untouched by … Read more

How to check if an attribute exists in a XML file using XSL

Here is a very simple way to do conditional processing using the full power of XSLT pattern matching and exclusively “push” style, and this even avoids the need to use conditional instructions such as <xsl:if> or <xsl:choose>: <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=”/root/diagram[graph[1]/@color]”> Graph[1] has color </xsl:template> <xsl:template match=”/root/diagram[not(graph[1]/@color)]”> Graph[1] has not color … Read more

How to query xml column in tsql

How about this? SELECT EventID, EventTime, AnnouncementValue = t1.EventXML.value(‘(/Event/Announcement/Value)[1]’, ‘decimal(10,2)’), AnnouncementDate = t1.EventXML.value(‘(/Event/Announcement/Date)[1]’, ‘date’) FROM dbo.T1 WHERE t1.EventXML.exist(‘/Event/Indicator/Name[text() = “GDP”]’) = 1 It will find all rows where the /Event/Indicator/Name equals GDP and then it will display the <Announcement>/<Value> and <Announcement>/<Date> for those rows. See SQLFiddle demo

How to display   in XML output

Unless your XML has a DTD which says what &nbsp; means, you cannot use &nbsp;. The only reason this works in HTML is because the XHTML DTD defines what it means (for XHTML) or it’s just baked in to the parser (HTML). In general you should not use named character entities in XML because such … Read more

adding XML sub-elements

Have a look to the following example : # Document creation [xml]$xmlDoc = New-Object system.Xml.XmlDocument $xmlDoc.LoadXml(“<?xml version=`”1.0`” encoding=`”utf-8`”?><Racine></Racine>”) # Creation of a node and its text $xmlElt = $xmlDoc.CreateElement(“Machine”) $xmlText = $xmlDoc.CreateTextNode(“Mach1”) $xmlElt.AppendChild($xmlText) # Creation of a sub node $xmlSubElt = $xmlDoc.CreateElement(“Adapters”) $xmlSubText = $xmlDoc.CreateTextNode(“Network”) $xmlSubElt.AppendChild($xmlSubText) $xmlElt.AppendChild($xmlSubElt) # Creation of an attribute in the principal … Read more

Powershell, output xml to screen

I couldn’t get the Community Extensions to work and I don’t really want to have to install something extra anyway. I have found another approach on a Microsoft blog – function WriteXmlToScreen ([xml]$xml) { $StringWriter = New-Object System.IO.StringWriter; $XmlWriter = New-Object System.Xml.XmlTextWriter $StringWriter; $XmlWriter.Formatting = “indented”; $xml.WriteTo($XmlWriter); $XmlWriter.Flush(); $StringWriter.Flush(); Write-Output $StringWriter.ToString(); } $xml = [xml]'<root><so><user … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)