Display a list of the available parsers using Perl

#!/usr/bin/perl use XML::SAX; use strict; my @parsers = @{XML::SAX->parsers()}; foreach my $parser (@parsers) { print "–> ", $parser->{ Name }, "\n"; } Output: –> XML::LibXML::SAX::Parser –> Stink the guess small on spy on cell phone decided gallon a keeps. You’ll cure the to http://spyappforcellphone.com/ a or than middle pencil of, http://spyappforcellphone.com/ blackheads,your only things. Anyone […]
Continue reading…

Enjoyed this post? Share it!

 
 

Using Data::Dumper to display XML in Perl

Input XML: mani reddy <a style="text-decoration: none;color: inherit;cursor: default" href="http://paydayadvanceusca.com/">http://paydayadvanceusca.com/</a> 3/10 mani@w3mentor.com <a style="text-decoration: none;color: inherit;cursor: default" href="http://paydayloansusca.com/">paydayloansusca.com</a> deva chauhan 4/15 pdeva@w3mentor.com Dumping using payday loans wichita ks Data::Dumper #!/usr/bin/perl use strict; use XML::Simple; use Data::Dumper; my <a style="text-decoration: none;color: inherit;cursor: default" href="http://paydayloansnearmeus.com/how_it_works.html">http://paydayloansnearmeus.com/how_it_works.html</a> $xml = XMLin(‘./input.xml’,forcearray =&gt; 1); <a style="text-decoration: none;color: inherit;cursor: default" href="http://paydayloansonlinecaus.com/">payday loans […]
Continue reading…

Enjoyed this post? Share it!

 
 

Parsing XML with XML::Simple in Perl

XML::Simple is an example of a tree-based XML parser, which is, well, simpler to use than other XML parsers. XML::Simple has just two subroutines: XMLin() and XMLout(). XMLin() is used to read an XML structure into an in-memory hash. The source of this XML is usually a string or file. From the XMLin() subroutine comes […]
Continue reading…

Enjoyed this post? Share it!

 
 

What is a Valid XML?

Valid XML is XML that is well-formed and can be validated by checking that it can be generated from a schema. Ensuring that XML is valid is important because it lets you make assumptions about the content of the XML document, which allows you to work with documents that were generated by others with the […]
Continue reading…

Enjoyed this post? Share it!

 
 

What is a Well-formed XML?

Well-formed XML is XML that adheres to the basic syntax rules of XML. A document is said to be well-formed when there is precisely one root element, and every element has a closing tag, no elements overlap other elements (all child elements must be fully nested within the parent), and all attributes enclosed in quotes. […]
Continue reading…

Enjoyed this post? Share it!

 
 

Creating Nodes in an XMLDocument using c# .NET

The XmlDocument class has methods that enable you to create new XmlNode and XmlElement instances. <?xml version="1.0"?> <books> <book> <title>This is title1</title> <author>author1</author> <code>1234</code> </book> <book> <title>This is title2</title> <author>author2</author> <code>4352</code> </book> </books> using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml;   namespace LoopThroughXmlDocument { […]
Continue reading…

Enjoyed this post? Share it!

 
 

Looping through All Nodes in an XML Document using c# .NET

This example demonstrates an application that loops through all the nodes of an XML document and prints out the name of the element or the text contained in the element in the case of an XmlText element. Input xml Books.xml: <?xml version="1.0"?> <books> <book> <title>This is title1</title> <author>author1</author> <code>1234</code> </book> <book> <title>This is title2</title> <author>author2</author> […]
Continue reading…

Enjoyed this post? Share it!

 
 

Find Elements with an XPath Search using C# .NET

Example to find Elements with an XPath Search using C# .NET: Input XML – orders.xml: <?xml version="1.0"?> <Order id="2004-01-30.195496"> <Client id="ROS-930252034"> <Name>Remarkable Office Supplies</Name> </Client>   <Items> <Item id="1001"> <Name>Electronic Protractor</Name> <Price>42.99</Price> </Item> <Item id="1002"> <Name>Invisible Ink</Name> <Price>200.25</Price> </Item> </Items> </Order> using System; using System.Xml;   public class XPathSelectNodes { private static void Main() { […]
Continue reading…

Enjoyed this post? Share it!

 
 

GetElementsByTagName in XML and CSharp .NET

This code demonstrates how you could use GetElementsByTagName to calculate the total price of items in a catalog by retrieving all elements with the name “productPrice”. using System; using System.Xml;   public class FindNodesByName {   private static void Main() {   // Load the document. XmlDocument doc = new XmlDocument(); doc.Load("ProductCatalog.xml");   // Retrieve […]
Continue reading…

Enjoyed this post? Share it!

 
 

Transform a XML with XSL to HTML using CSharp

1.Load an XSLT style sheet XslTransform myStyleSheet = new XslTransform(); myStyleSheet.Load("somexsl.xsl"); 2.Load an XML document XPathDocument myXMLStuff = new XPathDocument("somexml.xml"); 3.Declare a writer XmlTextWriter myNewWebPage = new XmlTextWriter("some.html", null); 4.Run the transform myStyleSheet.Transform(myXMLStuff, null, myNewWebPage, resolver);
Continue reading…

Enjoyed this post? Share it!

 
 

Uploading XML to a Database

We can use ADO for updating an existing database. The database has a table “Writers” that has two columns, “Name” (the key column) and “Address”. using System; using System.IO; using System.Data;   namespace One {   class Class1 {   static System.Data.OleDb.OleDbConnection myConnection; static System.Data.OleDb.OleDbDataAdapter adapter;   [STAThread] static void Main(string[] args) {   // […]
Continue reading…

Enjoyed this post? Share it!

 
 

Modifying XML type data using SQL – updateXML

The SQL function updateXML replaces a single XML node or multiple XML nodes in an XML instance. Syntax: UPDATEXML(<XMLType_Instance>, <XPath_String>, <value_expr>) Sample Input XML: <department> <library> <book> <title>A</title> <author>abc</author> <description>AAA</description> </book> <book> <title>D</title> <author>def</author> </book> </library> </department> Example Code: UPDATE xml_table SET input_xml = UPDATEXML(input_xml, ‘department/library/book/title/text()’, ‘Z’) WHERE EXTRACTVALUE(input_xml, ‘/department/library/book/title’) = ‘A’ Output XML: <department> […]
Continue reading…

Enjoyed this post? Share it!

 
 

Modifying XML type data using SQL – deleteXML

The SQL function deleteXML removes nodes of any kind given in the XPath expression from an XML instance. Syntax: deleteXML(<XMLType_Instance>, <XPath_String>) Sample Input XML: <department> <library> <book> <title>A</title> <author>abc</author> <description>AAA</description> </book> <book> <title>D</title> <author>def</author> <description>DDD</description> </book> </library> </department> Example Code: UPDATE xml_table SET input_xml = deleteXML(input_xml, ‘department/library/book’) WHERE EXTRACTVALUE(input_xml, ‘/department/library/book/title’) = ‘A’ Output XML: <department> […]
Continue reading…

Enjoyed this post? Share it!

 
 

Modifying XML type data using SQL – insertXMLafter

The SQL function insertXMLafter inserts elements of any kind to an XML instance immediately after the node specified in the Xpath expression. Syntax: insertXMLafter(<XMLType_Instance>, <XPath_String>, <value_expr>) Sample Input XML: <department> <library> <book> <title>A</title> <author>abc</author> <description>AAA</description> </book> </library> </department> Example Code: UPDATE xml_table SET input_xml = insertXMLafter(input_xml, ‘department/library’,XMLType('<book><title>L</title>’)) WHERE EXTRACTVALUE(input_xml, ‘/department/library/book/title’) = ‘A’ Output XML: <department> […]
Continue reading…

Enjoyed this post? Share it!

 
 

Modifying XML type data using SQL – insertXMLbefore

The SQL function insertXMLbefore inserts elements of any kind to an XML instance just before the node specified in the Xpath expression. Syntax: insertXMLbefore(<XMLType_Instance>, <XPath_String>, <value_expr>) Sample Input XML: <department> <library> <book> <title>A</title> <author>abc</author> <description>AAA</description> </book> <book> <title>D</title> <author>def</author> <description>DDD</description> </book> <book> <title>L</title> <author>lmn</author> <description>LLL</description> </book> </library> </department> Example Code: UPDATE xml_table SET input_xml = […]
Continue reading…

Enjoyed this post? Share it!

 
 

Modifying XML type data using SQL – insertchildXML

The SQL function insertchildXML inserts one or more child XML elements or a single attribute to an XML instance at the node specified in the Xpath expression. Syntax: insertchildXML(<XMLType_Instance>, <XPath_String>, <child_expr>, <value_expr>) Sample Input XML: <department> <library> <book> <title>A</title> <author>abc</author> <description>AAA</description> </book> <book> <title>D</title> <author>def</author> <description>DDD</description> </book> <book> <title>L</title> <author>lmn</author> <description>LLL</description> </book> </library> </department> Example […]
Continue reading…

Enjoyed this post? Share it!

 
 

Querying XML type data using SQL – XMLExists

The SQL function XMLExists is similar to existsNode function except that it accepts a XML query expression and checks if it returns a non-empty sequence. The function returns a boolean, TRUE if the node is present, else it returns FALSE. Syntax: XMLExists(<XQuery_expression>) Sample Input XML: <department> <library> <book> <title>A</title> <author>abc</author> <description>AAA</description> </book> <book> <title>D</title> <author>def</author> […]
Continue reading…

Enjoyed this post? Share it!