Friday, April 8, 2011

Counting XML Source Lines of Code


Counting XML Source Lines of Code

December 9, 2008 · Filed Under General, Software Estimating, Software Sizing  - 2 Comment(s)
A customer recently asked how to count XML for their software sizing activity.  Turned out the question was more detailed than just the syntax.  They really wanted to know IF they should count XML and, if using lines of code, if they should adjust the XML lines.  They pointed out that many of their projects include up to 25% XML lines.
This has been updated based on the latest research January 2009: The bottom line is that XML, while it has no procedural statements (it is a data declaration language), can require significant effort in software development and should be counted. While your own data is most precise there are approximation methods listed below. To model XML in SEER-SEM, you need to look at how it is developed or generated.
1. If sizing with SLOC using XML based size estimates
a. If XML is being generated, you can use the Code Generator kbase and put XML lines into pre-existing size
b. If XML is developed by hand, you can put the XML lines into New
2. If sizing with SLOC using 3GL new size equivalents
a. If XML is being generated, multiply 3GL size by 0.2 (or 0.15, 0.20, 0.25 for a range) (see spreadsheet for a workup)
b. If XML is developed by hand, multiply 3GL size by 0.57
3. If sizing with Functions
a. If XML is generated, you can simply put the functions in as new as use the Code Generator Function Implementation Mechanism
b. If XML is developed by hand, you can put function in as new and select the XML Function Implementation Mechanism
———–

Counting XML

XML is interesting to count since an XML document generally doesn’t actually do anything… that is, XML does not include procedural code. XML is pure declarations wrapped in tags. There is an if statement that can change the value of an element, not program logic. XML Separates Data from HTML. With XML, data can be stored in separate XML files so you can concentrate on using HTML for layout and display and ensure changes in the underlying data will not require any changes to the HTML.
The following are the generic logical source line counting rules:


Logical Source Line Rules
Include
Exclude
Control statements (DO While, DO Until, GOTO etc.)
Mathematical statements (ex: i = a*b)
Conditional statements (IF, THEN, ELSE)
Deliverable Job Control (JCL) statements
Data declarations
Data typing and equivalence statements
INPUT/OUTPUT format statements

Blank lines
BEGIN statements from Begin-End pairs (count one line only for each pair)
Non-delivered programmer debugging statements
Continuation of formatting statements
Machine or library-generated data statements

XML Include

XML statements that should be counted fall into the categories of

  • Data declarations
  • Data typing and equivalence statements
  • INPUT/OUTPUT format statements
  • Compiler Directives (Job Control Type Language)
Each XML element declaration included an opening and a closing tag… So we can count closing tags </
XML declaration statements, not data declarations: <? ?>
An XML element is everything from (including) the element’s start tag to (including) the element’s end tag.

Example XML Element: <body>Today is a wonderful day</body>

General XML Counting Rules

COUNT: Most Elements can be counted automatically by counting: Non comment Line terminating closing tag </
COUNT: Additional Non comment Line Beginning <!
COUNT: And Additional Non Comment Line Beginning <?
The above can be automated simply. Additionallly if initial declarations that don’t generate XML are counted (they should be a very small percentage) then
OPTIONALLY COUNT: Count attributes and compiler declarations >

XML Exclude

Comments: <!– –>
Blank Lines
Looking at an example XML schema cobbled from www.w3schools.com/xmlNote this is fragments of xml cobbled together for the example. This is not cohesive XML but fragments to illustrate the issues.
<?xml version=”1.0″ encoding=”ISO-8859-1″?> Compiler Declaration 1
<?xml-stylesheet type=”text/css” href=”cd_catalog.css”?> Extensible stylesheet declaration 2
<img src=”computer.gif”> XML Attribute
Compiler declaration
3
<a href=”demo.asp”> XML Attribute
Compiler declaration
4
<bookstore> partial  
< !DOCTYPE note [      Count non-comment <! 5
<!ELEMENT note (to,from,heading,body)>
  6
<!ELEMENT to (#PCDATA)>
  7
<!ELEMENT from (#PCDATA)>
  8
<!ELEMENT heading (#PCDATA)>
  9
<!ELEMENT body (#PCDATA)>
  10
]>     Partial 11
     
<person sex='female'>     attribute 12
<!—This is a comment --> comment  
<book category="COOKING"> partial  
<title lang="en">Everyday Italian</title>   13
<author>Giada De Laurentiis</author>   14
<year>2005</year>   15
<price>30.00</price>   16
</book>   17
<book category="CHILDREN"> partial 18
<title lang="en">Harry Potter</title>   19
<author>J K. Rowling</author>   20
<year>2005</year>   21
<price>29.99</price>   22
</book>   23
<book category="WEB"> partial  
<title lang="en">Learning XML</title>   24
<author>Erik T. Ray</author>   25
<year>2003</year>   26
<price>39.95</price>   27
</book>   28
</bookstore>   29

No comments:

Post a Comment