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

Similar Articles

[PageSpeed] 46

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:

FRx
Dear, I encountered problem of changing default base period. The version of FRx software is 6.5.28 and it is running under Windows 2K Professional. The situation was: After opened the Catalog of Report Window, there was a pop-up message box which said 'Changed the default base period to C'. I did not know why this could happen. - Would you please tell me under what circumstances this pop-up message box would display?? In order to continue to use this software, I only could click 'OK' from the message box. The report date is then changed to 'Default Base Period' - (Ja...

Works in 2003 but not 2007
When I reference the below function in 2003 I get function displayed... now in 2007 I get #NAME? Any idea what I need to change/set in 2007 so it will run this function? Function formulaText(x As Range) 'returns the text equivalent of formula in upper left cell in range x 'example: =formulatext(a1) returns the formula found in cell a1 of active worksheet 'example: =formulatext(a1:b5) returns the formula found in cell a1 of active worksheet formulaText = x.Cells(1, 1).Formula End Function Thanks, Mark Mark, It works fine for me. Are you stored in a stan...

Need Hyperlink from Menu Page to work in email
I have a workbook with several tabs. First tab is a "menu" type page (summary of other pages). Currently I have hyperlinks to all the other pages from the menu page. What I want to be able to do is copy the menu page into an email and enable the users to click on the existing hyperlinks (whatever adjustments needed) to go directly to their page of the workbook. Using Excel 2007. Please advise how to do this and what changes may be need for both options to work. ...

One Element, one attribute
Well, despite reading an excellent article on ComplexTypes, I am unsure on the quickest way to express the following <myElem myAttrib="noMoreThan30chars"> No More than 30 chars </myElem> Both on the string are SimpleContent, right? Thanks, Mark BTW the article is http://www.xml.com/pub/a/2001/08/22/easyschema.html Hi Mark, The following schema will do what you need: <?xml version="1.0" encoding="utf-8" ?> <xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified"...

Rule to forward mail to external address doesn't work
It might be an XCON issue but I didn't find the corresponding group so I post my questions here. I set up a rule that when an email arrives if my name is in the "to" or "cc" field then forward the email to another external SMTP address for example an hotmail address. however this rule never works through. It's a Exchange 2003 SP1 on Windows 2003 SP1 I have no problem to manually forward the email to that external SMTP address; If forward to an mailbox in our Exchange Org, it works; I turned on diagnostic for Transport, no error or warning logged; I tracked mes...

Setting default program for viewing pictures
How do I set the default program for viewing picture attachments? I use Outlook Express 6 and when I click to open an attached picture it opens to JASC Paint Shop Pro 8 but no picture appears. In the past Explorer opened up my pictures. Can any one give me the steps to change the default from paint Shop to Explorer?? Hi Digitdan, Change the program that starts when you open a file http://office.microsoft.com/assistance/preview.aspx?AssetID=HP051925951033&C TT=1&Origin=EC790000701033&QueryID=bSa5KrD4N0&Query=Change+the+program+that+ starts+when+you+open+a+file&Scop...

IF formula not working
Can anyone tell me why this IF formula isn't working? =IF(D5<E5<F5,"A",IF(D5>E5>F5,"B", IF(D5<E5>F5,"C",IF(D5>E5<F5,"D","F")))) It's returning "B" every time. D5, E5, and F5 are all derived from formulas. Is that the problem? I appreciate any help! TRy =IF(AND(D5<E5,E5<F5),"A", IF(AND(D5>E5,E5>F5),"B", IF(AND(D5<E5,E5>F5),"C", IF(AND(D5>E5,E5<F5),"D","F")))) -- HTH Bob "MelissaS&qu...

How to change default printing parameters on Excel & ......
How to change the default printing parameters on Excel & keep them changed for future workbooks. Example: Normally I use Printing margins 0.25 on all directions, but default printing margins are 0.75. I want to change them to set 0.25 as DEFAULT. If you start a new workbook and change the page layout (for all the sheets), you can save it into your XLStart folder as Book.xlt. Excel will use that as the basis for new workbooks. You can change a lot of settings that way--including orientation, headers/footers.... Amjad wrote: > > How to change the default printing parameters ...

The " from" field always sports the default email for all replies
Hello all, I am a windows mail user on my Vista home premium on Dell XPS M1330. I have several emails configured on my windows mail and one of it configured as default email. All the emails of the configured accounts show up in the dropdown list of "from" field with the default email selected while creating a new email which I can select to choice. For all emails (accounts) I have set the respective unique HTML signature using the advanced button. My problem When I receive email on accounts other than the default email and when I click to reply to those em...

Working on Staffing grid
I'm working on a staffing grid to determine the number of staff neede depending on the number of clients. Licensed staff = 1:5 ratio Assistant = 1:8 ratio What is the formula so if I enter the number of clients it gives m two separate values (one for Licenced, 1 for assistant)into tw separate cells. Simple to do but I'm new to this -- cardingt ----------------------------------------------------------------------- cardingtr's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2702 View this thread: http://www.excelforum.com/showthread.php?threadid=...

calculating the work week
Is there a way to calculate the workweek in a particular year, given the year, month, day, and the day number in that year such as 115. I thought maybe using strftime would work, but it always returns the current time, date, and workweek. This is what I tried: CString CUtilities::ConvertDaysToWeekOfYear(CString year, CString month, CString day, CString yeardays) { CString tmp; tmp.Format("Days of Year: %s\nMonth: %s\nDay: %s\nYear: %s\n",yeardays,month,day,year); MessageBox(tmp); struct tm *newtime; time_t aclock; CString returnString; int iWorkWeek; time(&aclo...

Why does copy and paste between eMails not work?
Copy no longer copies to the clipboard. Is there a setting I have deleted somewhere? Using Windows 7 and Office 2007 proffessional. Does it work if you restart outlook? Do you have any addins installed that could be erasing the clipboard? I've seen this happen with addins and contacts, but not email. to test, open the new message form before copying so you just need to copy and switch to the other message. (http://www.slipstick.com/Contacts/clipboard.htm) -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Cent...

Unable to access exchange server with entourage (however other methods do work)
When I try to connect to our exchange server with entourage, all i get is the following message: Error -3176: The server can't be found. Be sure the mail server information is entered correctly in the Account Manager, and that your DNS settings in the Network Control Panel are correct. The strangest part is that i can access our exchange server through webmail (no problem) or through apple's mail.app (no problem) either. Can someone help? On Thu, 28 Oct 2004 14:16:12 -0500, Laurent Lamblin wrote (in article <2004102821161216807%hush@skynetbe>): > The strangest part ...

Modify Excel default cell width for Access export file
I am exporting a file from MS Access to MS Excel, and I would like to modify the default cell width in the Excell file. I tried creating a workbook template with modified cell widths and save it to the XLSTART folder. This works for new workbooks created in Excel, however, for the exported report files via Access, the cell width is not crrying through. Any suggestions? Thanks to all who respond. Gary ...

Outlook and Hotmail -- now works again! For some not all?
Received from MS: <<Recently, Hotmail� announced that ... Hotmail will no longer allow new e-mail accounts to be accessed via Microsoft� Office Outlook� and Outlook Express. [BUT....] <<We are pleased to inform you that because you are an existing and valued customer, at this time your current Hotmail and MSN account(s) are exempt from this restriction and you will be able to continue enjoying access to those accounts from Outlook or Outlook Express. However, any new Hotmail or MSN accounts you create will not be accessible via Outlook or Outlook Express.>> ....an "...

attribute size not changed in mapping view
I changed the size of an attribute to 50 but when I go to relationships and try to map the attribute I see the size in ( ) as 100 still and I get an error message stating the source entity attribute is too large to map to the target entity attribute. I am trying to map a new attribute new_building from account to billto_line2 in order request form. The new attribute was originally created with maximum length of 100 but I have changed the length to 50. I can go into attributes and see the maximum length as 50. Billto_line2 is nvar 50. I am running CRM 3.0. I published all my changes a...

Question about XML schema and blank element
Hey there, I'm running into an issue and wondered if any of you XML gurus know a solution. I'm currently using XML as a data transport mechanism between two applications and an XML schema for format validating purposes. Whenever I have an child element that is nested inside another element, the child element must not be empty or I get the following error message: "'Element' is an invalid node type." I've worked around this by adding a filler element as the first child element with junk as the inner text. The error only occurs if the FIRST child element is empt...

Setting the default browser to MSN
I would like Outlook to use my MSN client as the browser (rather than IE) when I click on a web link. Does anyone know how to do this? TIA. </joel> Control panel, internet options, programs tab.... msnews.microsoft.com wrote: > I would like Outlook to use my MSN client as the browser (rather than > IE) when I click on a web link. Does anyone know how to do this? TIA. > > </joel> Joel, If using Windows XP, right-click the Start Button, choose Properties, click the Customize button, in the drop-down list under "Show on Start menu" and choose MSN. HTH...

Setting Defaults in Create table statement?
How do you do the equivalent to the following in Access 2000? No matter what I try I get a syntax error: CREATE TABLE SQLProcs ( RecID AUTOINCREMENT , Name VarChar(50) NOT NULL , SysOrAppDB VarChar(50) NOT NULL DEFAULT 'A', <--- I can't figure out how to set a DEFAULT using SQL in access!?!?! RebootDSLIfRebuilt Bit NOT NULL DEFAULT 0, RebuildIfExists Bit NOT NULL DEFAULT 0, CreateString TEXT NULL ) You may have to execute it programmatically under ADO for that approach to work. This kind of thing: CurrentProject.Connection.Execute "C...

setting default Printer in EXCEL VBA via API
Hi, I have an issue with some code I'm trying to produce. Though at the moment I feel like i wish i hadn't started! :P I am producing a batch printing script for some drawing register spreadsheets I have. Basically I need to be able to set the default printer in WINDOWS from within VBA to different printers (printers setup with the default print settings to different page sizes) depending upon wether a certain cell contains the text A4-A3-A2-A1 or A0. These will be controling External documents from PDF's to AutoCAD drawings and therefore this needs to be using the windows defa...

Combo Boxes stop working in Access 2003 when you install Office 2
After installation of Office 2003 SP3 a combo box in an existing database no longer displays the contents of the list. See http://support.microsoft.com/kb/945674 -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "burnzie_13" <burnzie_13@discussions.microsoft.com> wrote in message news:807A4875-48DF-4F4A-8ECE-43642F90A70C@microsoft.com... > After installation of Office 2003 SP3 a combo box in an existing database > no > longer displays the contents of the list. ...

Default "Save as Type" problem
Outlook 2003 - when saving an e-mail message "save as type" defaults to HTML. This unfortunately strips off the attachments. I need to change to Outlook Unicode type as a default, but when changing settings in Tools - Options - Other - Advanced Options - "Use unicode message format when saving" when ticked on - doesn't seem to make any difference. Default still appears as HTML. Can anyone help Thanks, Georg ...

Schema validation using Visual Studio .NET 2003
Hi, All Iam trying to do is validate a group of schemas which inturn references an external XSD schema(tried putting both in local webserver/as part of project),Iam getting errors This is what Iam doing 1. Open a blank Biztalk solution 2. Add all the schemas to validate 3. Validate Schema Am not sure what Iam doing wrong.Any help would be appreciated Thanks Raj ...

=+COUNTIF(D10:D240,"Yes") NOT WORKING
Hello all, I know little about Excel that's why i am posting this message here. I have a sheet with several columns, one of those columns have always one of this 2 values: YES or NO My question is, is there a way to count how many YES or NO are in that column and display the number in other cell? I already tried =+COUNTIF(D10:D240,"Yes") but i get a msg saying my form have an error. Thanks in advance, Helder Portugal Tried out your :=+COUNTIF(D10:D240,"Yes") - works ok (it did not give any error msg) Try : =COUNTIF(D10:D240,"*Yes*") "Helder"...

Public folder default display
Hi, I have an Exchange server 5.5 and I make some forms used by the clients to publish information in public folders. My problem is : How create a default display (server side) for a public folder used by Outlook clients. In my case I want a chronology display. Thank you Michel ...