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
1653 Views

Similar Articles

[PageSpeed] 35

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:

Application works on one PC but not on another with same OS?
Hi, My application works OK on my PC (Windows 2000, latest server pack) but not on my colleague's (same OS and SP). One difference is that I have the .NET IDE installed on my machine, and he doesn't. I used to have the same problem on my machine. An error was generated because (IIRC) I was using an MFC string comparison method on a char array. This worked in my debug config., but not in the release config. I replaced the code with a strcmp method, and that fixed it on my machine, but not on his. Is there something I should update in his Window's installation when I install the ap...

how to format :send picture with message: as a default
each time i sent a graphic i must go to the format and click "send picture with message." how do I make this a default so it is there permanently.I am running on a Windows XP and am using Outlook Express for my mail. LYNNY <LYNNY@discussions.microsoft.com> wrote: > each time i sent a graphic i must go to the format and click "send > picture with message." how do I make this a default so it is there > permanently.I am running on a Windows XP and am using Outlook Express > for my mail. Ask in an Outlook Express newsgroup. -- Brian Tillman ...

CDO eMail messages not working from FoxPro since installing KB8929
We installed the Exchange 2000 Update (KB892986) and since then our code that creates CDO eMails errors out with the following message: "OLE IDispatch exception code 0 from CDO.Message.1: The transport lost its connection to the server." We are planning to reverse thes updates over the weekend. Does anyone know a better way around this? ...

Exchange delegation using group doesn't work?
Hi, I am running Exch 2k3 SP1 in Windows SBS 2003. I tried to delegate Exch to user. What I did: I created a group called: Junior Admins I delegate at the Exchange top level the Junior Admins group to be Exch Full Admin. I assigned user: Sam to Junior Admins I use AdminPak.msi for Sam to control Exchange from her PC. Sam can get ESE on her PC (mmc), but can't open the server folder due the rights. I've also assigned Sam in the local administrator of that workstation. Things work if I assign Sam directly in the Delegation Control from ESE. How can I delegate control via group? ...

Exchange 2003 installed SP2 now IMF is not working.
I had Exchange 2003 SP1 and installed the IMF. I heard that SP2 has the IMF bulit-in. During the SP2 install it said I had to uninstalled the old IMF, which I did. I then installed Exchange 2003 SP2, I see the tabs in the "System Manager", Global Settings, "Message Delivery" But no IMF portion under the SMTP. I tried to reinstalled the IMF but still it doesn't show up under the SMTP protocals. What am I doing wrong? Within system manager, go to protocols|smtp and select Properties, the Advanced button and then the edit button. Then select the checkbox for en...

alter default view for operations
I'd like to just see parameter types, not names. I don't want to see: methodName( in request : LongRequestObjectName ) : ResponseObjectName I'd like to see: methodName( LongRequestObjectName ) : ResponseObjectName -------------- Justin ...

Calculating working hours #2
Hi All, I'm hoping someone can help me with the following problem. I need to create a formula which calculates the different between two date/time values excluding out of business hours. Here's an example. A1: 21/06/2005 10:00:00 A2: 23/06/2005 14:30:00 When using "=(B1-A1)*24" I can the result 52.5 If the business hours are between 08:30 and 17:00 the actual result required is 21.5 I hope this makes sense. Thanks in advance, Mo.. Try this =(INT(A2)-INT(A1))*8.5+(MOD(A2,1)-MOD(A1,1))*24 -- HTH Bob Phillips "Mohammed Zenuwah" <MohammedZenuwah@discu...

Excel not working correctly
We have a pc here that does not operate correctly when using Excel. She can't run queries from templates or even worksheets that have calculations in them. If she uses them then they won't work anymore on other pc's. Her computer seems to be very strange. For some reasons the formulas in excel are not the same. They do not work in hers so we have to change them. Example, it should bring information from other cells and use the average formula. It will not work in certain areas so we had to create a formula manually that adds the cells together and then divides by t...

FileFormatConverts.exe stopped working
I have been using the converter without problem for docx. to .doc. It has stopped working - no changes to my system to explain. I am using MS Office SP3. Convert documents from Outlook Express 6. It now opens Word, the "Convert File" dialogue box appears, choose "Word 2007 Document", it says "word is converting ...", and "MSWord: There was an error opening the file". Not exactly helpful. Went to Add/Remove Programs, chose "repair". Rebooted computer. Opened msg in mail again and same error msg. Uninstalled Converter prog...

Work expenses/reimbursement #2
Hi, I am new to money and I am using the 2005 trial version. I was wondering if there is a way to exclude company expenses from my expense reports and reimbursement from my income reports. Any help would be greatly appreciated. If they are tracked as particular categories, then the easiest way would be to customize those reports to exclude the categories you don't want to see. -- Glyn Simpson, Microsoft MVP - Money http://money.mvps.org Check http://support.microsoft.com/default.aspx?scid=fh;EN-GB;mny for UK tips and fixes for MS Money. To send Microsoft your wishes or suggestions, ...

create xml document based from schema
I have the following schema. I need to know how to make an xml document based from it. The main worry I have is the DateTime field. <?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="NewsArticle"> <xs:complexType> <xs:sequence> <xs:element name="Description" type="xs:string" /> <xs:element name="Body" type="xs:string" />...

Creating a new default message template
I have a email template that I want to make the default. In other words, when you click on New to create a new email, I want the message template that I have created to come up as the default. Does anyone know how to do this? What you are proposing is a very bad idea. Using a custom form as the = default for new messages will guarantee that non-Outlook recipients = won't be able to read attachments you send.=20 I'd suggest that you back up and explain what functionality you were = hoping to add by changing the message form, and in what version of = Outlook.=20 --=20 Sue Mosher, ...

i have office basic 2003,does IRM work with basic?
i have office basic 2003,does IRM work with basic? and how do i get it to work Office basic? Standard Edition? Small Business Edition? Small Business Management Edition? IRM? Information Resource Management? "Oola" <Oola@discussions.microsoft.com> wrote in message news:B52FCE24-0C62-4D47-9F0B-548290487BEE@microsoft.com... >i have office basic 2003,does IRM work with basic? and how do i get it to >work Information Rights Management depends on having a Windows 2003 server with the IRM bits installed. Since Office Basic comes with OEM computers, I will presume tha...

Search folders Otlk-2003 don't work?
I create a new search folder in OUtlook folder with the criteria, "mail to and from certain people". And then I choose a person from the list. The email address for that person has always been the same. However the search folder only comes up with mail I have SENT to that person, not mail they have sent to me. Whats with that? thanks... jf ...

'Signature for new messages' which won't work
Hi, I have Outlook 2003 and if I go to Tools>Options>Mail Format I see I can choose a signature for new messages. I have 3 e-mail accounts set up, and have set a new message signature for each one, e.g.: 1) Home > Sig 1 (default) 2) Work > Sig 2 3) Play > Sig 3 However when I try to create a new e-mail message, it seems impossible to automatically start a new e-mail using my Work or Play accounts, and therefore have the signature automatically entered. So what is the point of this feature if there is no way to use it? I'm sure I'm missing so...

Changing default address book from Global to Contacts
I would like to change the Outlook 2000 default of listing the Global Adress book from our internal network to opening our shared business contacts when you click the "To:" button when addressing a new email. Does anybody know how to accomplish this? Thank you in advance. Go to Tools > Options > Addressing Tab and choose which Contacts folder to show first. -- Russ Valentine [MVP-Outlook] "Brad Streeeer" <brad@aerospecialties.com> wrote in message news:0b2501c3c3f4$f69d8220$a501280a@phx.gbl... > I would like to change the Outlook 2000 default of listing &...

email defaults to personal folder
Hello we have run into a new problem at my work. About 5 new people started recently and the all tried to open their email accounts before they were properly setup. Because no server was entered they now have a top folder called "Personal Folders". What we have been doing to fix the situation is to right click on the outlook icon choose > properties > email accounts > Add a new email account. This method then adds the user's mailbox to outlook. The problem however is that we have lost old calendar information as well as the mail defaults to the personal folder ...

enter-key works with two inputboxes but not with olny one.
Hi, There is a form with two inputboxes and a submit button.The focus is on the first inputbox. When the user presses the enter-key without having entered some text, the javascript message "wrong text" appears. This works. But if i remove the second inputbox, leaving only the first inputbox and the submit button, pressing the enter-key without any text does not show the javascript message. Nothing happens. The focus remains in the inputbox. You can see the page is postbacked, but that's all. Why does it work with two inputboxes and not with one? And how to fix...

Vertical alignment does not work
In a worksheet I have, I have set the vertical alignment to 'Top' however, the text seems to stay at the bottom. Navigation Right click > Format Cells > Alignment tab. Merge cells is checked Has anyone encountered this bug (one-off)? Ms Excel 2007 Click on the cell and delete anything before the first character... "Jon" wrote: > In a worksheet I have, I have set the vertical alignment to 'Top' however, > the text seems to stay at the bottom. > > Navigation > Right click > Format Cells > Alignment tab. > Merge cells is checked >...

Links won't work in emailed enewsletter, help!
Some links in my e-newletter are unactive when I email it. I've tried to secure the text box with an exact position by going to the text box format options and it won't even let me select this as an option. Any other suggestions? For hyperlinks to work the newsletter has to be HTML. Have you tried using a PDF for your newsletter? You can make the hyperlinks active in a PDF file. Do this search for a free converter. Not all of them have the feature you want. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "JulieCCD&qu...

why does email outlook 2003 not work?
I HAVE BEEN USING OUTLOOK EXPRESS FOR E-MAIL, BUT MY OUTLOOK 2003 HAS NEVER WORKED, WHAT DO I NEED TO DO? A little more detail might be helpful. For example, did you configure an account in Outlook? Did you import your account settings in from Outlook Express? When Outlook 2003 tries to check for mail, do you get any error messages? Heck, is the problem where Outlook 2003 doesn't start and/or does it give an error message has to why? "TEFAL" <TEFAL@discussions.microsoft.com> wrote in message news:8B457207-6722-4FF7-A647-B6D2E90ED718@microsoft.com... >I HAVE B...

comparing 2 similar columns on seperate work sheets in 1 workbook
How can I compare a column from worksheet 1 to a column in worksheet 2 of the same work book? BTW, the cell my have a number or text in it but not formulas "Dan" wrote: > How can I compare a column from worksheet 1 to a column in worksheet 2 of the > same work book? What are you looking for? If you want to find out if each cell in Column A of sheet1 appears in column A of sheet2, you could use a helper column of formulas: =isnumber(match(a1,sheet2!a:a,0)) and drag down And you could use the same kind of formula that will tell you if values in sheet2 appear in sheet1. ...

Defaults in Publisher 2003
Is there a way of changing defaults in Publisher 2003. Specifically I want to: * set default measurement unit to centimeters * set default border of a text box to black line, .75 pt * set Tools menu>Commercial Printing Tools>Fonts so that TrueType fonts are always embedded. Many thanks Chris ...

Combo box default value multiautocomplete
Hi All i have a subform with 10 item. The first one is a combo box that can choose the value from a list that is linked to a table with many record. This subform is related to the master form with link master field codice,cognome,nome link child field codice,cognome,nome that are the other items that are not visualize in the subform. These link give me the right connection to the master form. Normally when i choose the value from list (table) i place also all the other item in the subform using this code in after update precedure Me.ISEE.Value = Me.ISEE.Column(0) Me.F_Costo_con_M...

Web hyperlinks: default browser and resulting browser window size?
Hi, Am using Excel 97 (I know it is old but I like it!) with Windows XP Pro (SP2). Have a series of web hyperlinks in a worksheet, that load the current chart for a specified chart, from Yahoo Finance. For example: http://chart.finance.yahoo.com/c/1y/c/tls.ax will load the chart for the Australian telco "Telstra". All the links work just fine but have two questions: 1) My default internet browser is Firefox but the links always open Internet Explorer. Is there a way to ensure that Firefox is used? 2) The loaded chart appears in a maximised IE window. Which is a bit silly as t...