View RSS Feed

Development Team Blog

Play the VDF15.1 RC1 Quiz

Rate this Entry
I'd like to talk about two of the changes made in our Visual DataFlex 15.1 Release Candidate (VDF15.1 RC1). We wrote a new help section about XML namespaces (Reference Library / General Reference / XML Namespaces Primer). That's the good change. We accidentally copied the wrong XML file into our new workspace template section. That's the evil change. Now when you try to create a new workspace you get the following error:



The error is reported here and the fix for it is found here.

Coincidentally the cause of this error can be explained by information provided in the XML Namespaces Primer. It seemed like this might be a good chance to test our new documentation. Can you tell us why the Studio reported this error?

Here is some extra information. The Studio raised this error when it tried to open and read our "empty" DDClassList.xml file. The file is a properly constructed XML file but the Studio immediately recognized that the file was wrong. Here's the bad file:
Code:
<DataDictionaryList  xmlns="http://www.dataaccess.com/VisualDataFlex/2008/DataDictionaryList/">
    <DDClasses/>  
</DataDictionaryList>
The file that would have worked looks like this:
Code:
<DataDictionaryList  xmlns="http://www.dataaccess.com/VisualDataFlex/2006/DataDictionaryList/">
    <DDClasses/>  
</DataDictionaryList>
In addition, this file would have worked as well:
Code:
<DataDictionaryList  xmlns="http://www.dataaccess.com/VisualDataFlex/2008/DataDictionaryList/">
    <Tables/>
</DataDictionaryList>
Here's another clue. We changed the format of the DDClassList.xml file in VDF14.1. If the Studio encounters an old format file it automatically converts it to the newer format. In this case, it didn't even try.

And one last clue. Every single node in this bad XML file is wrong!

The question to you is, why did the Studio decide that the XML file in RC1 is invalid? The answer is in the XML Namespaces primer. You will have to download and install RC1 to read this primer.

You get extra credit if you can write the code that would recognize that the file is invalid.

(Perhaps we even added this bug to RC1 to get you all to read the new help section. Could we possibly be that clever?)
Categories
Uncategorized

Comments

  1. Anders Ohrt's Avatar
    The pre-14.1 format used the ".../2006/..." namespace, and it's second level node was <DDClasses>. The 14.1+ format used the ".../2008/..." namespace, and it's second level node was <Tables>. So, the 15.1 Studio first searches for a <Tables> node in the 2008 namespace first (like your third example). Not finding it, it dropped back to searching for a <DDClasses> node in the 2006 namespace (like your second example), for migration. But, it did not find this node either. So, it gave the error.
  2. Anders Ohrt's Avatar
    And here's for the extra credit:

    Code:
    Define C_2006_NS for "http://www.dataaccess.com/VisualDataFlex/2006/DataDictionaryList/"
    Define C_2008_NS for "http://www.dataaccess.com/VisualDataFlex/2008/DataDictionaryList/"
    
    Handle hoXML hoDataDictionaryList hoChild
    Boolean bOk
    
    Get Create (RefClass(cXMLDOMDocument)) to hoXML
                   
    Set psDocumentName of hoXML to "C:\DDClassList.xml"
    Set pbAsync of hoXML to False
    Set pbValidateOnParse of hoXML to False
    Get LoadXMLDocument of hoXML to bOK
    
    // 2008 root with 2006 child?
    Get ChildElementNS of hoXML C_2008_NS "DataDictionaryList" to hoDataDictionaryList
    If (hoDataDictionaryList <> 0) Begin
        Get ChildElementNS of hoDataDictionaryList C_2008_NS "DDClasses" to hoChild
        If (hoChild <> 0) Begin
            Send Stop_Box "XML has 2008 NS root with 2006 NS child"
            Send Destroy of hoChild
        End
        Send Destroy of hoDataDictionaryList
    End
    
    // 2006 root with 2008 child?
    Get ChildElementNS of hoXML C_2006_NS "DataDictionaryList" to hoDataDictionaryList
    If (hoDataDictionaryList <> 0) Begin
        Get ChildElementNS of hoDataDictionaryList C_2006_NS "Tables" to hoChild
        If (hoChild <> 0) Begin
            Send Stop_Box "XML has 2006 NS root with 2008 NS child"
            Send Destroy of hoChild
        End
        Send Destroy of hoDataDictionaryList
    End
    
    Send Destroy of hoXML
  3. John Tuohy's Avatar
    Anders' answers are pretty much perfect. Next time I'll make the quiz harder.

    If your XML document uses namespaces you always want to pay attention to the full name of the element and that full name is the name of the namespace plus the element name. The name of the prefix can be anything and it is only used to find the namespace name. The namespace and prefix are bound using the xmlns attribute. If the format is in the form of xmlns:preName=nsName, elements with a prefix of preName will belong to the nsName namespace. If the format is in the form of xmlns=nsName, this is a default namespace declaration and elements without a prefix will belong to the default nsName prefix. If you understand this you will understand why the following two XML documents are equal.
    Code:
    <DataDictionaryList  xmlns="http://www.dataaccess.com/VisualDataFlex/2006/DataDictionaryList/">
        <DDClasses/>  
    </DataDictionaryList>
    
    <dd:DataDictionaryList  xmlns:dd="http://www.dataaccess.com/VisualDataFlex/2006/DataDictionaryList/">
        <dd:DDClasses/>  
    <dd:/DataDictionaryList>
    This is why all of the namespace based messages (e.g., ChildElementNS, AddElementNS) are passed a namespace name and an element name. You don't really care what the prefix is.