xml interview questions
Top xml frequently asked interview questions
Is there a way to re-indent a block of code? I'm looking for somthing similar to Ctrl-Shift-F in eclipse (Auto-Format/Indent).
I'm willing to install a plugin if that's what's needed. NppAutoIndent won't work as I'll need it for XML, HTML and CSS.
Source: (StackOverflow)
Since AVD tools 16 I'm getting this warning:
Replace "..." with ellipsis character (..., …) ?
in my strings.xml
at this line
<string name="searching">Searching...</string>
How do I replace ... is it just literally: …
If someone could explain this encoding please?
Source: (StackOverflow)
I'm working in Java with XML and I'm wondering; what's the difference between an element and a node?
Source: (StackOverflow)
How do I comment out a block of tags in XML?
I.e. How can I comment out <staticText>
and everything inside it, in the code below?
<detail>
<band height="20">
<staticText>
<reportElement x="180" y="0" width="200" height="20"/>
<text><![CDATA[Hello World!]]></text>
</staticText>
</band>
</detail>
I could use <!-- staticText-->
but that's just for single tags (as what I know), like //
in Java and C. I would like something more like how /** comment **/
can be used in Java and C, so I can comment out longer blocks of XML code.
Source: (StackOverflow)
I saw the following line in an XML file:
xmlns:android="http://schemas.android.com/apk/res/android"
I have also seen xmlns
in many other XML files that I've come across.
What is it?
Source: (StackOverflow)
Using C# .NET 2.0, I have a composite data class that does have the [Serializable]
attribute on it. I am creating an XMLSerializer
class and passing that into the constructor:
XmlSerializer serializer = new XmlSerializer(typeof(DataClass));
I am getting an exception saying:
There was an error reflecting type.
Inside the data class there is another composite object. Does this also need to have the [Serializable]
attribute, or by having it on the top object, does it recursively apply it to all objects inside?
Source: (StackOverflow)
How do I Deserialize this XML document:
<?xml version="1.0" encoding="utf-8"?>
<Cars>
<Car>
<StockNumber>1020</StockNumber>
<Make>Nissan</Make>
<Model>Sentra</Model>
</Car>
<Car>
<StockNumber>1010</StockNumber>
<Make>Toyota</Make>
<Model>Corolla</Model>
</Car>
<Car>
<StockNumber>1111</StockNumber>
<Make>Honda</Make>
<Model>Accord</Model>
</Car>
</Cars>
I have this:
[Serializable()]
public class Car
{
[System.Xml.Serialization.XmlElementAttribute("StockNumber")]
public string StockNumber{ get; set; }
[System.Xml.Serialization.XmlElementAttribute("Make")]
public string Make{ get; set; }
[System.Xml.Serialization.XmlElementAttribute("Model")]
public string Model{ get; set; }
}
.
[System.Xml.Serialization.XmlRootAttribute("Cars", Namespace = "", IsNullable = false)]
public class Cars
{
[XmlArrayItem(typeof(Car))]
public Car[] Car { get; set; }
}
.
public class CarSerializer
{
public Cars Deserialize()
{
Cars[] cars = null;
string path = HttpContext.Current.ApplicationInstance.Server.MapPath("~/App_Data/") + "cars.xml";
XmlSerializer serializer = new XmlSerializer(typeof(Cars[]));
StreamReader reader = new StreamReader(path);
reader.ReadToEnd();
cars = (Cars[])serializer.Deserialize(reader);
reader.Close();
return cars;
}
}
that don't seem to work :-(
Source: (StackOverflow)
I'm working on a little something and I am trying to figure out whether I can load an XDocument from a string. XDocument.Load()
seems to take the string passed to it as a path to a physical XML file.
I want to try and bypass the step of first having to create the physical XML file and jump straight to populating the XDocument.
Any ideas?
Source: (StackOverflow)
Is REST a better approach to doing Web Services or is SOAP? Or are they different tools for different problems? Or is it a nuanced issue - that is, is one slightly better in certain arenas than another, etc?
Bounty-Edit:
Now, almost three years later I would like to ask this question again - offering a bounty to encourage an indepth answer. I would especially appreciate information about those concepts and their relation to the PHP-universe and also modern high-end web-applications.
Source: (StackOverflow)
One mistake I see people making over and over again is trying to parse XML or HTML with a regex. Here are a few of the reasons parsing XML and HTML is hard:
People want to treat a file as a sequence of lines, but this is valid:
<tag
attr="5"
/>
People want to treat < or <tag as the start of a tag, but stuff like this exists in the wild:
<img src="imgtag.gif" alt="<img>" />
People often want to match starting tags to ending tags, but XML and HTML allow tags to contain themselves (which traditional regexes cannot handle at all):
<span id="outer"><span id="inner">foo</span></span>
People often want to match against the content of a document (such as the famous "find all phone numbers on a given page" problem), but the data may be marked up (even if it appears to be normal when viewed):
<span class="phonenum">(<span class="area code">703</span>)
<span class="prefix">348</span>-<span class="linenum">3020</span></span>
Comments may contain poorly formatted or incomplete tags:
<a rel='nofollow' href="foo">foo</a>
<!-- FIXME:
<a rel='nofollow' href="
-->
<a rel='nofollow' href="bar">bar</a>
What other gotchas are you aware of?
Source: (StackOverflow)
I have many rows in a database that contains xml and I'm trying to write a Python script that will go through those rows and count how many instances of a particular node attribute show up. For instance, my tree looks like:
<foo>
<bar>
<type foobar="1"/>
<type foobar="2"/>
</bar>
</foo>
How can I access the attributes 1 and 2 in the XML using Python?
Source: (StackOverflow)
I often find this strange CDATA
tag in XML
files:
<![CDATA[]]>
I have observed that this CDATA
tag always comes at the beginning, and then followed by some stuff.
But sometimes it is used, sometimes it is not. I assume it is to mark that some data
will be inserted after that. But what kind of data
? Isn't anything I write in XML tags some sort of data
?
Source: (StackOverflow)