Schema element default attribute does not work?

I have tried to set a default value in my schema element definition, but it 
does not seem to work. That is, when I try to "getElementsByTagName()" 
against a tag that was not specified in the xml, but _was_ defined in the 
xsd, I get an empty return. I expected to get an element that matches the 
default value.

I am using VBScript and MSXML6.0.

This is what my xsd looks like:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- definition of simple elements -->
<xs:element name="ScenarioName"       type="xs:string" />
<xs:element name="SimString"          type="xs:string" default="*" />

<!-- definition of complex elements -->
<xs:element name="run">
    <xs:complexType mixed="true">
        <xs:all>
            <xs:element ref="ScenarioName"       minOccurs="1" maxOccurs="1" 
/>
            <xs:element ref="SimString"          minOccurs="0" maxOccurs="1" 
/>
        </xs:all>
        <xs:attribute ref="runId" use="required" />
    </xs:complexType>
</xs:element>

<xs:element name="scenarioBatch">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="run" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>
</xs:element>

</xs:schema>

My xml file is:

<?xml version="1.0" standalone="no"?>

<scenarioBatch
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file:///C:/Scripts/ScenarioBatchList.xsd">

    <run runId="Run02">
        <ScenarioName>Rt_Batch1_Circular_RT_99X_2Hr_2RTA</ScenarioName>
    </run>
</scenarioBatch>

and my VBScript is:

    ' Load the scenario list from the file
    Set objsbxFile = CreateObject("Msxml2.DOMDocument.6.0")
    objsbxFile.validateOnParse = true
    objsbxFile.resolveExternals = true
    objsbxFile.async = false
    objsbxFile.load sbxFile
    if (objsbxFile.parseError.errorCode <> 0) Then
        Call DebugLogger(DebugLevelAlways, "Error loading SBX file (" & 
sbxFile & "): " & objsbxFile.parseError.reason)
        Wscript.Quit()
    end if

    set sbxRuns = objsbxFile.getElementsByTagName("run")
    
    ' show what was read
    for each Elem in sbxRuns
        Call DebugLogger(DebugLevelInfo, "RunId = " & 
Elem.getAttribute("runId"))
        set sbxScenarioNames = Elem.getElementsByTagName("ScenarioName")
        Call DebugLogger(DebugLevelInfo, "ScenarioName = " & 
sbxScenarioNames(0).nodeTypedValue)
        set sbxSimStrings = Elem.getElementsByTagName("SimString")
        Call DebugLogger(DebugLevelInfo, "SimString = " & 
sbxSimStrings(0).nodeTypedValue)
        
    Next

0
10/26/2009 7:29:01 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
1606 Views

Similar Articles

[PageSpeed] 57

PixelPusher wrote:
> I have tried to set a default value in my schema element definition, but it 
> does not seem to work. That is, when I try to "getElementsByTagName()" 
> against a tag that was not specified in the xml, but _was_ defined in the 
> xsd, I get an empty return. I expected to get an element that matches the 
> default value.

I think you misunderstand what default values for element means. If the 
element is empty then it takes on the default value. If the element is 
missing as in your sample then it is _not_ inserted.

See http://www.w3.org/TR/xmlschema-1/#cElement_Declarations
which says
    "{value constraint} establishes a default or fixed value for an 
element. If default is specified, and if the element being ·validated· 
is empty, then the canonical form of the supplied constraint value 
becomes the [schema normalized value] of the ·validated· element in the 
·post-schema-validation infoset·. "

-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/
0
mahotrash (1777)
10/27/2009 10:41:05 AM
Martin,
Thanks for the information. That is what I was starting to suspect. I was 
hoping to not need to know the default values of elements in the schema 
within the code that interprets the xml. I guess that is not possible.

Thanks again.
Thom


"Martin Honnen" wrote:

> PixelPusher wrote:
> > I have tried to set a default value in my schema element definition, but it 
> > does not seem to work. That is, when I try to "getElementsByTagName()" 
> > against a tag that was not specified in the xml, but _was_ defined in the 
> > xsd, I get an empty return. I expected to get an element that matches the 
> > default value.
> 
> I think you misunderstand what default values for element means. If the 
> element is empty then it takes on the default value. If the element is 
> missing as in your sample then it is _not_ inserted.
> 
> See http://www.w3.org/TR/xmlschema-1/#cElement_Declarations
> which says
>     "{value constraint} establishes a default or fixed value for an 
> element. If default is specified, and if the element being ·validated· 
> is empty, then the canonical form of the supplied constraint value 
> becomes the [schema normalized value] of the ·validated· element in the 
> ·post-schema-validation infoset·. "
> 
> -- 
> 
> 	Martin Honnen --- MVP XML
> 	http://msmvps.com/blogs/martin_honnen/
> .
> 
0
10/27/2009 1:18:10 PM
Reply:

Similar Artilces:

schema error
Hi all ! My app is a asp .net page that validate a xml using a schema. But it only works (validate the xml file) when i replace the namespace "http://tempuri.org/" in xml and xsd files with a physical path of my app "c:\inetpub\wwwroot\xml\". How can i use the virtual path ? Thank's for any help. Can you post your xml and xsd? Thanks, Priya "fivemagic" <fivemagic@bol.com.br> wrote in message news:D64E1F6E-B2B0-4592-B3FB-97E491D9EF9A@microsoft.com... > Hi all ! > > My app is a asp .net page that validate a xml using a schema. But it onl...

eConnect Schema for Purchasing Returns
Hi, Does anyone know if there are plans to release a schema for Purchasing Return transactions? Regards Konrad ...

nested attributes
Hi, I want to define a class for the following XML: <root> <id value="350006357" /> <key value="90B1B94C4DAE9C207E67C48432DC3004126A7F53EF48A0E7F58AF227D2749908" /> </root> I do not want to use nested classes for the 'id' and 'key' nodes. What attribute(s) should I put in front of the corresponding members of my class? Thx in adv Eric ...

Default Watermark
There is a watermark "001" printed on every first page of every excel spreadsheet printed from this computer. It is printed in grey and angled upwards. It does not show in print preview and it is not a setting in the printer configs on this machine. Any ideas? Thanks ...

hyperlinks to specific link don't work when published to html #2
I have a table of contents in excel where each line hyperlinks to a specific sheet in another workbook. When I publish it ( i.e.convert to html ) pressing the hyperlinks always gets me to the same sheet. How can I get it to go to the correct sheet even after I publish it ? (experts-exchange seems to have an answer but i can't afford the membership) I've been publishing by saving in the mhtml format. Thanks- Joe ...

Error when creating an attribute
Hi all, I just installed MS CRM Server(Small business Server).When I create an attrribute and try to save it I get the following error: Line:92 Char:1 Error:could not complete the operation due to error 80020101 I also tried to solve it by installing rollup 1 update but still given problems. Thanks in advance -- donn ...

validating against schema with namespaces
I have a very complex XDR schema that uses namespaces: xmlns="urn:schemas-microsoft-com:xml-data" xmlns:b="urn:schemas-microsoft-com:BizTalkServer" xmlns:d="urn:schemas-microsoft-com:datatypes" Do I need to build a custom validator in order to validate XML documents against this schema? How does the XML parser know how to validate against the extra namespaces? For example, schemas-microsoft-com:datatypes allows for attributes such as maxLength, minLength, etc. If my XML document contains a value that doesn't meet these criteria, then the document should n...

Excel
When entering or editing formulas in Excel2000 I find myself by habit using cursor keys when editing formulas. Instead of moving the cursor this inserts cell references which I find annoying. A quick Googling reveals that pressing F2 switches to edit mode where the cursor keys work as I want them to. Are there any settings in Excel2000 so that by default it uses edit mode, not only on cell formulas but also in data validation or conditional formatting formula boxes? > A quick Googling reveals that pressing F2 switches to edit mode where the > cursor keys work as I want them to...

MSCRM work w/ MACs in future?
Does anyone know if the CRM 1.2 release is going to work with MAC OS 10? I have a client that runs a mixed enironment, and claims that OS 10 was built to bridge the gap between MAC and Windows operating systems. Anyone know about anything about it? John? TIA, Eric Hello Eric no word on support for apple OSX. Trust me when I say that OSX was not built to bridge the gap between MAC and Windows's OS The client is definately misinformed in this area. OSX is simply apple's next operating system. as to OSX support in 1.2 - I have to say I would be VERY suprised but that is only my opin...

HELP PLEASE
All my buttons on my forms all the sudden give me a "Error accessing file. Network connection may have been lost" when i click them. When i try to create new buttons the same things happens. Please tell me there is a way to correct it??? Any Hope?! "Adam" <Adam@discussions.microsoft.com> wrote in message news:512F8581-E4A5-4C83-B560-15C0AD19E8CB@microsoft.com... > All my buttons on my forms all the sudden give me a "Error accessing > file. > Network connection may have been lost" when i click them. When i try to > create new buttons the s...

Can't Get Public Folders Working
Hi I'm running Exchange Enterprise 2003 on a Win2k03 server, but despite repeated tries, I can't get public folders to work. In Exchange System Manager, I can create a new folder just fine, but shortly thereafter as I check the various properties tabs, I get an "Unexpected Error" message. Upon closing and reopening System Manager, the new public folder is no longer present. I'm wondering if the fact that we're not using the default web site/settings in IIS has something to do with it. But all other aspects of Exchange work well. Could it be permissions? I'm in as...

CreateForm from template does not seem to work properly
I have a form (frm_Graph_Template) that contains a bunch of controls. I would like to copy and modify the form programmatically. I assumed that the CreateForm( , template) function would copy the form and all the controls on it, but that does not appear to be the case. It copies the form, but none of the controls. Is this the intended purpose of this Method? If so, I guess I will have to write a loop that looks through all of the controls on the original and duplicates them in the copy using the CreateControl method. Dale -- email address is invalid Please reply to newsgroup only....

Parsing XML Schema, How To, please
Hi! I have an Excel 2003 Schema I need to parse to extract elements names. I am puzzled which System.Xml object can help me. Here's the example of my schema: I need to get a collection of element names(TemplateB62,TemplateC62 ......) <?xml version='1.0' encoding='UTF-8'?> <xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/XMLSchema.xsd"> <xsd:annotation>XSD Schema generated with Excel XML Toolbox...

How do I change the default paste settings in Word 2008?
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Hi there - <br><br>I need to paste everything as unformatted text. Is incredibly time consuming to select Paste Special and then select unformatted text. Can someone help explain how I can change it to a keyboard command or something that makes it more efficient for me to paste unformatted text? <br><br>Thanks! Unfortunately there is no available setting for doing so. The only option is an Apple Script for the purpose but I'm afraid I haven't held on to a copy of it. You may be able to dig it out...

Default Database Folder
Hi, I have an application wherein it has lot of reports and i have enabled the option to export the same onto Word/Excel (the default button that access provides to do so). I am accessing this application through a network drive. So when I export, I want these exported word/excel files to sit in that network drive. This problem will be solved if i am able to prompt the save file as dialog box, which I am not able to. Could anyone please let me know your valuable thoughts on the following things: 1) Prompt Save File as dialog box when exporting report. 2) change the default database fo...

Schema.ini for multi-row import?
I've got some data which is basically just an outputted report. I need to create one record out of a file that is like NAME ACCOUNT ADDRESS1 ADDRESS2 <JUNK> PHONE etc.etc. Each record is the exact same layout and separated by a page break. I know if each record was on one line the schema.ini would be pretty easy to make. Can a multi-row schema.ini file be set up? Thanks. Mike L. Hi Mike, As far as I know there's no way of getting the text file driver to use FF - Chr(12) - as the record separator: it assumes you want to use CR+LF - Chr(1...

Set up default chart
I always use the same chart type (XY), and am tired of changing the font size, background color, etc. every time I create a new chart. Is there a way to change the default settings for new charts? Thank you, Rob Rob wrote on Tue, 31 Jan 2006 16:06:18 -0400: R> I always use the same chart type (XY), and am tired of R> changing the font size, background color, etc. every time I R> create a new chart. Is there a way to change the default R> settings for new charts? R> Thank you, R> Rob You might want to look into templates. Try Help for a start. Templates are...

VC IDE 'go to definition' doesn't work
Hello and thanks for trying ti help, This problem has been driving me nuts, the 'go to definition' item in the context menu in .cpp files always says "symbol 'symbol' undefined". It will find something defined in MFC, but IT WONT FIND ANYTHING DEFINED IN MY PROJECT. Yes I have deleted the .clw file and have rebuilt and run, what else could be causing this problem??? I tried posting this in the vc.ide.general newsgroup a few weeks ago. Thanks, Ivan "Ivan Starr" <ivan@ivanstarr.com> wrote in message news:%23l3ANp9oDHA.2528@TK2MSFTNGP12.phx.g...

Default values
Hello! I'm (still) making my dynamic charts from access to excel. Everything's working just fine, except the fact that all properties (like gridelines, legend position, axis names...) are set to default values, and I want to modify them. Does anyone know how and why are they set to default properties? Thanks, you've been most helpfull so far! Ana -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/excel-chart/200906/1 Basically the steps are: select a chart that with the formatting required; right-click the chart and choose Chart Type; check the "...

Attach Link does not work if file name has changed
I used MS Money Plus Home and Business. I keep scanned copy of Invoices in one folder. I link them to MS Money. After linking the item in MS money to the file, a link icon appears in MS money. When I change the name of the scanned file, the link does not work any longer. There is no way of knowing whether the item (that still has a link icon) has a valid link or not (because the scanned file name changed)? Rajesh Sorry - the question was "Is there a way of knowing whether the item (that still has a link icon) has a valid link or not (because the scanned file name changed)?" ...

How to move all dbo schema objects to another schema?
Does anyone know of a way to move all objects in a db from schema dbo to another schema? mat (mat@notarealdotcom.adr) writes: > Does anyone know of a way to move all objects in a db from schema dbo to > another schema? In theory: SELECT 'ALTER SCHEMA newschema TRANSFER dbo.' + quotename(name) FROM sys.objects WHERE schema_id = 1 Excute and run result. But before you go ahead, beware of that in practice it is a lot more difficult. For starters you should probably add a WHERE clause to the SELECT, so that you don't include object types like cons...

Code generation with types from other schemas
I want to be able to define types in one schema, and then use them in other schemas. So far so good. Now I also want to be able to generate classes from these schemas and use them independantly, and in their own namespaces. For example, schema1.xsd ==> schema1.cs schema2.xsd ==> schema2.cs where there are types from schema1 used in schema2. When I use xsd.exe to generate schema2.cs and an <xs:import> element, it works, but also regenerates the types from the schema1.cs. I guess the question is, is there a simple way to generate code for what I'm trying to do, or do I n...

Outlook does not reply on default
This is a second posting for the problem as the answer did not resolve the problem. I have come across this problem. There are two accounts set up, one PRO and one PB. The PRO is set as the default account. Now though when a reply is sent, the PB account is used to send the email instead of the PRO account which is the one defined as default. I have noticed that an email from a person not sent on either a PB or PRO address still has it's reply sent on the PB account. We would have thought that it should send on the default account unless the reply was to a person sending on...

Creating new attribute with Lookup as data type
I need to create a new attribute with Lookup as data type in the Account entity just like system Parent Account (parentaccountid) attribute in account entity, it would be great if I can just uplicate this system attribute. Since the new attribute (Dealer of Record) will be pointing to the same entity as parentaccountid, what is the best way go about doing this? Thanks. To achieve this you will have to create a new entity which will contain attributes you require and then you will have to set a many to one relationship between Account and your entity. After creating the entity y...

Bought MS Money on ebay
FYI... I have MS Money Plus Premium and the online service expired a few days ago. I bought a new, still in the wrap copy of MS Money Plus Deluxe 2008. I know that's not the same title as my Plus Premium but gave it a try anyway. I asked the seller to send me the activation code ahead of the CD, which he did but the code didn't work for activating a service extension. Perhaps when I install using the CD (on a different computer to test it), it will allow me to: 1) activate the online service; 2) use the same data files from Plus Premium, so I can update stock quotes. Again,...