Category Archives: Xml

Any reason not to use XmlSerializer?

Questions: I just learned about the XmlSerializer class in .Net. Before I had always parsed and written my XML using the standard classes. Before I dive into this, I am wondering if there are any cases where it is not the right option. EDIT: By standard classes I mean XmlDocument, XmlElement, XmlAttribute…etc. Answers: There are… Read More »

C# : Getting all nodes of XML doc

Questions: Is there a simple way, to get all nodes from an xml document? I need every single node, childnode and so on, to check if they have certain attributes. Or will I have to crawl through the document, asking for childnodes? Answers: In LINQ to XML it’s extremely easy: XDocument doc = XDocument.Load(“test.xml”); //… Read More »

How to serialize a List<T> into XML? [closed]

Questions: How to convert this list: List<int> Branches = new List<int>(); Branches.Add(1); Branches.Add(2); Branches.Add(3); into this XML: <Branches> <branch id=”1″ /> <branch id=”2″ /> <branch id=”3″ /> </Branches> Answers: You can try this using LINQ: List<int> Branches = new List<int>(); Branches.Add(1); Branches.Add(2); Branches.Add(3); XElement xmlElements = new XElement(“Branches”, Branches.Select(i => new XElement(“branch”, i))); System.Console.Write(xmlElements); System.Console.Read();… Read More »

How to get root node attributes on java

Questions: I have an xml file like down below. I want to get pharmacies nodes’ latitude and longitude attributes.I can get chilnodes attributes but couldnt get root node attributes. I am new on java and xml. I could not find a solution how to do. <pharmacies Acc=”4″ latitude=”36.8673380″ longitude=”30.6346640″ address=”Ayujkila”> <pharmacy name=”sadde” owner=”” address=”dedes” distance=”327.000555668″… Read More »

Oracle 10g: Extract data (select) from XML (CLOB Type)

Questions: I’m new in Oracle and I’ve – maybe trivial – a problem in a select. (I’m using Oracle 10g Express Edition). I’ve a DB with a field CLOB: mytab.xml This column have an XML like this: <?xml version=”1.0″ encoding=”iso-8859-1″?> <info> <id> 954 </id> <idboss> 954 </idboss> <name> Fausto </name> <sorname> Anonimo </sorname> <phone> 040000000… Read More »

Special Characters in XML

Questions: I am creating a left navigation system utilizing xml and xsl. Everything was been going great until I tried to use a special character in my xml document. I am using &raquo; and I get th error. reason: Reference to undefined entity ‘raquo’. error code: -1072898046 How do I make this work? Answers: You… Read More »

Parsing XML using unix terminal

Questions: Sometimes I need to quickly extract some arbitrary data from XML files to put into a CSV format. What’s your best practices for doing this in the Unix terminal? I would love some code examples, so for instance how can I get the following problem solved? Example XML input: <root> <myel name=”Foo” /> <myel… Read More »

Exclude attribute from a specific xml element using xslt

Questions: I am new in xslt. I have the following problem. I need within an xml, to remove a specific attribute (theAttributein the example) from a specific element (e.g. div). i.e. <html> <head>…</head> <body> <div id=”qaz” theAtribute=”44″> </div> <div id =”ddd” theAtribute=”4″> <div id= “ggg” theAtribute=”9″> </div> </div> <font theAttribute=”foo” /> </body> </html> to become… Read More »

How to count distinct values in a node?

Questions: How to count distinct values in a node in XSLT? Example: I want to count the number of existing countries in Country nodes, in this case, it would be 3. <Artists_by_Countries> <Artist_by_Country> <Location_ID>62</Location_ID> <Artist_ID>212</Artist_ID> <Country>Argentina</Country> </Artist_by_Country> <Artist_by_Country> <Location_ID>4</Location_ID> <Artist_ID>108</Artist_ID> <Country>Australia</Country> </Artist_by_Country> <Artist_by_Country> <Location_ID>4</Location_ID> <Artist_ID>111</Artist_ID> <Country>Australia</Country> </Artist_by_Country> <Artist_by_Country> <Location_ID>12</Location_ID> <Artist_ID>78</Artist_ID> <Country>Germany</Country> </Artist_by_Country> </Artists_by_Countries> Answers: If… Read More »

Category: Xml

Converting an XML file to string type

Questions: How can we write an XML file into a string variable? Here is the code I have,the variable content is supposed to return an XML string: public string GetValues2() { string content = “”; XmlTextWriter textWriter = new XmlTextWriter(content, null); textWriter.WriteStartElement(“Student”); textWriter.WriteStartElement(“r”, “RECORD”, “urn:record”); textWriter.WriteStartElement(“Name”, “”); textWriter.WriteString(“Student”); textWriter.WriteEndElement(); textWriter.Close(); return contents; } Answers: Something… Read More »