Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    XML Namespaces (xmlns) and DataSource

    Hello Isomorphic,

    I am trying to load an xml file into a DataSource using:
    dataFormat: 'xml'
    dataURL: < path to my xml file >
    clientOnly: true

    My xml snapshot has 6 or 7 namespace declarations peppered through the document. In this format, I cannot get the data to load correctly. If I move all the namespaces to the root node, it will work fine. This xml will eventually come from a web service I have no control over, so moving the namespaces is not a real solution.

    I've snooped through the code, and following it the best I can it looks like the 'selectNodes' method in the XMLDoc is being called for my valueXPath statements (which have xmlns aliases on them). I've checked the 'namespaces' parameter that is passed in, but it is always undefined. The comment in the codes says something about the default namespaces as well as the namespaces on the "document element" should be available. By "document element" I'm guessing this is in ref to the xml documentElement aka root node?

    It looks as if the namespaces param should be able to be passed to the selectNodes method, but DataSource is calling this on my behalf. It further looks that namespaces can be set on a DataSource operationBinding, which I tried to send via xmlNamespaces on a type 'fetch', but it didn't seem to have any effect.

    My question is how do I get this style of xml to load?

    Thanks,

    #2
    Define the namespace prefixes via the xmlNamespaces property on either the OperationBinding or the DataSource as a whole. If that's not working, your code is incorrect, post it.

    Comment


      #3
      Didn't realize xmlNamespaces is part of DataSource, but adding that doesn't seem to help. Here's some test code and data to recreate the problem. The Develper console reports this error:

      Code:
      WARN:Log:[Exception... "An attempt was made to create or change an object in a way which is incorrect with regard to namespaces"  code: "14" nsresult: "0x8053000e (NS_ERROR_DOM_NAMESPACE_ERR)"  location: "http://<...>/XMLTools.js Line: 1528"]
      Test Case:
      Code:
      isc.defineClass('TestData', DataSource);
      isc.TestData.addProperties({
          dataFormat: 'xml',
          recordXPath: "//n0:customer",
          clientOnly: true,
      	
      	xmlNamespaces: {
      		xs:  "http://www.w3.org/2001/XMLSchema",
      		xsi: "http://www.w3.org/1999/XMLSchema-instance", 
      		xsd: "http://www.w3.org/1999/XMLSchema",
      		n0:  "http://xml.unresolvedns.org/types0",
      		n1:  "http://xml.unresolvedns.org/types1",
      	},
      
          fields: [{
              name: 'id',
              title: 'ID',
              type: 'text',
              valueXPath: 'n0:id',
              primaryKey: true
          }, {
              name: 'firstname',
              title: 'First Name',
              type: 'text',
              valueXPath: 'n0:name/n0:firstname'
          }, {
              name: 'middleinitial',
              title: 'Middle Initial',
              type: 'text',
              valueXPath: 'n0:name/n0:middleinitial'
          }, {
              name: 'lastname',
              title: 'Last Name',
              type: 'text',
              valueXPath: 'n0:name/n0:lastname'
          }, {
              name: 'address',
              title: 'Address',
              type: 'text',
              valueXPath: 'n0:address'
          }]
      });
      var data2 = isc.TestData.create({dataURL: 'data2.xml'});
      
      isc.defineClass('TestForm','DynamicForm');
      isc.TestForm.addProperties({
          autoDraw: false,
          autoFetchData: true,
          titleOrientation: "left",
          fixedColWidths: true
      });
      
      
      isc.Page.setEvent('load',function(){
          isc.VLayout.create({
              autoDraw: true,
      
              members: 
              [
      	        isc.TestForm.create({dataSource: data2}),
              ]
          });
      
      });
      Test XML (data2.xml)
      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <root> 
      
      	<n0:customer	 		
      		xmlns:xs="http://www.w3.org/2001/XMLSchema"
      		xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" 
      		xmlns:xsd="http://www.w3.org/1999/XMLSchema"
      		xmlns:n0="http://xml.unresolvedns.org/types0"
      		xmlns:n1="http://xml.unresolvedns.org/types1"
      		>
      
      	    <n0:id xsi:type="xs:token">
      	        DATA2
      	    </n0:id>
      		<n0:name xsi:type="n0:fullname">
      		    <n0:firstname xsi:type="xs:normalizedString">
      		        Jane
      		    </n0:firstname>
      		    <n0:middleinitial xsi:type="xs:token">
      		        E.
      		    </n0:middleinitial>
      		    <n0:lastname xsi:type="xs:normalizedString">
      		        Doe
      		    </n0:lastname>
      		</n0:name>
      	    <n0:address xsi:type="xs:string">
      	        2 Easy Street
      			Anywhere, CA, 12345-1234
      	    </n0:address>
      	</n0:customer>
      </root>

      Comment


        #4
        DataSource should not be clientOnly. When you have a clientOnly DataSource with a dataURL, it does a one time fetch expecting a specific data format covered in the docs. Remove the clientOnly flag, and if you want a clientOnly DataSource that works with this data, create it separately.

        Comment

        Working...
        X