[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
Re: [xml-dev] Help with XML anti pattern
- From: "G. Ken Holman" <gkholman@CraneSoftwrights.com>
- To: ihe.onwuka@gmail.com,William David Velasquez <wd@creativosdigitales.co>
- Date: Tue, 23 Nov 2021 14:11:56 -0500
Won't attributes for natural language and names
restrict the field values somewhat? Of course not
in raw Unicode characters, but if an exotic name
requires element structure to specify characters
of the name, that isn't available in attributes.
Very (very!) much an edge case, but I've just
avoided putting natural language into attributes.
I like what William is suggesting with the
element names as they uniquely label the semantic
associated with the element values:
<FirstName>Erick</FirstName>
<LastName>Rich</LastName>
<SWName>FancySoft v.1.0</SWName>
If the contractor wants to preserve the
"name/value" concept, I think attributes would be
appropriate for labeling the semantic along the lines of:
<value name="FirstName">Erick</value>
<value name="LastName">Rich</value>
<value name="SWName">FancySoft v.1.0</Value>
If you are looking for arguments why what you
have been given is awkward in XML processing,
addressing siblings with the same name but
different semantics can be awkward because of the
overlap of siblings. Of course one could address
the immediately following sibling, there are more
opportunities, I think, for ambiguity.
Consider in the original data that there are
three <Value> elements that follow as siblings to
the first <Name> element. Yes, the
immediately-following <Value> element is the
right one, but if this approach is meant, also,
to address absent values, then the
immediately-following <Value> element might be
following a different <Name> element.
I consider sibling names with differing semantics
to be poor structure design and I try to avoid it
at all costs. I think it increases the cost of
maintenance and it increases the opportunity for ambiguity.
I hope this helps.
. . . . . Ken
At 2021-11-23 13:49 -0500, Ihe Onwuka wrote:
If you made FirstName, LastName and SWName
attributes of SWMakerInfo wouldn't that satisfy both parties.
On Tue, Nov 23, 2021 at 1:21 PM William David
Velasquez <<mailto:wd@creativosdigitales.co>wd@creativosdigitales.co> wrote:
Hi XML folks,
I want to share here a real case to ask for your wisdom and advice:
This week my company started to work in a
project involving a customization of UBL
Invoices. A team before us, defined a structure
similar to this for receiving the name of a
person and the name of a software product:
<ext:UBLExtension>
 <ext:ExtensionContent>
  <SWMaker>
   <SWMakerInfo>
     <Name>FirstName</Name>
     <Value>Erick</Value>
     <Name>LastName</Name>
     <Value>Rich</Value>
     <Name>SWName</Name>
     <Value>FancySoft v.1.0</Value>
   </SWMakerInfo>
 </SWMaker>
 </ext:ExtensionContent>
</ext:UBLExtension>
This way of modeling data is opposite to the
essence of XML, but frequently used by
programmers that sells it as "flexible" because
it can accommodate future uses with new
combinations for elements "Name" and "Value"
(and because many programming languages
translate object dictionaries to this kind of XML).
The problem arrives when XPath expressions
become more complex (although not impossible to write) to access data:
For example, to get the first name:
ext:UBLExtension/*:ExtensionContent/SWMaker/SWMakerInfo/Name[
. = "FirstName" ]/following-sibling::Value[1]
But this kind of expression is not trustworthy.
For example, if the first <Value> element is
missing, the LastName will be returned instead.
I'm asking for your help, because we'll have a
meeting with the contractor and I need arguments
to convince them of changing to a
"Natural" XML structure like this:
<SWMaker>
 <SWMakerInfo>
   <FirstName>Erick</FirstName>
   <LastName>Rich</LastName>
   <SWName>FancySoft v.1.0</SWName>
 </SWMakerInfo>
</SWMaker>
I'm expecting customer won't be open to accept
the change, because the actual structure can do the work.
So, what arguments would you use to convince the customer?
Thanks in advance for all your input. It is very
enriching to read your opinions and learn from all your experience.
Â
--Â
William David Velasquez
Creativo de Software
Creativos Digitales S.A.S.
--
Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/x/ |
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Streaming hands-on XSLT/XPath 2 training class @US$125 (5 hours free) |
Essays (UBL, XML, etc.) http://www.linkedin.com/today/author/gkholman |
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]