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
773 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 (1778)
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:

eConnect Schema
Can someone point me to the correct Schema/XML node to enter data to the Transaction Entry screen found in the path Transactions, Financial, Batches, Transaction button ? I believe that would be <taGLTransactionLineInsert>.... -- Bud Cool Microsoft Certified Business Management Solutions Specialist, GP 9.0 Financials Currently supporting: GP 9.0, SP2 "DavidM" wrote: > Can someone point me to the correct Schema/XML node to enter data to the > Transaction Entry screen found in the path Transactions, Financial, Batches, > Transaction button ? > > > ...

Project table schema changes in 9.0
I upgraded a server from GP 8.0 sp5 to GP 9.0 sp2 last weekend. All seems to work fine so far. I have some Crystal Reports that were in the process of being developed and I have questions about 3 Project tables. These tables each have had fields removed. My question is...Where has the data these fields represented been relocated? Has the upgrade taken data from these tables and moved it to other tables? PA10721 -> PA31101 -> PA31102 -> *** Lists the fields added and removed in Project tables *** C:\Program Files\Microsoft Dynamics\GP 9.0 SDK\Content\8.0to9.0\PaTableDetailed_...

how does the INSERT INTO SQL work??
I have a similar post about 8 posts down, I think the answer has to do with the INSERT INTO statement. I don't know how to use it though =( =( =( & I can't figure it out to save my life. here's my guess on it, INSERT INTO TableName(Field2, Field3, Field4) VALUES (abc,def,123) that'll create a new row in the table, Field1 (column A) will be blank Field2 = abc Field3 = def Field4 = 123 Field5 = (blank) ? Thanks~ You're almost bang on. The only problem is that the SQL you presented will fail, because you don't have quotes around the strings. You need: INSERT I...

RUS not working on Exchange 2003 since KB873333 applied
I am running Exchange 2003 SP1 on Windows 2003. Since I applied the latest Microsoft updates (Feb 2005) the RUS is not working. I removed the KB873333 update and the RUS is working again. Has anyone else experienced this issue? DalyB I am experiencing this issue as well . . . has anyone found a solution to this, besides removing the patch? Don't want to test in a live enviroment, but I'm building a virtual today to see if I can duplicate the RUS not updating the user's e-mail addresses. Thanks "DalyB" wrote: > I am running Exchange 2003 SP1 on Windows 2003. S...

xsd.exe errors with schemas importing other schemas
Hi, I am working with XSD.exe vs.net command line util. I have an XSD that I am trying to use to generate classes with. However, the XSD references another schema and the XSD.exe is having trouble finding the referenced schema. Does anyone have an example of what the command line params would be so that the tool is aware of all schemas? Does the tool have trouble with the XSD lines: xmlns:r="somewhere.files.referencedxsd" <xs:import schemaLocation=".\referencedxsd.xsd" namespace="somewhere.files.referencedxsd" /> <xs:element ref="r:ReferencedRo...

xml schema: elements with unique attribute values.
Hi all. I�m a bit newbie writing xml schemas. Is it possible to define xml element that must have unique attribute values in same level. For example if i have a xml - document: <list> <subsection name="first"> <!-- subsection contents --> </subsection> <subsection name="first"> <!-- ERRROR!!! --> <!-- subsection contents --> </subsection> <subsection name="second"> <!-- subsection contents --> </subsection> </list> Schema: <xs:complexType n...

setting to page width by default
I have users who like the page width view but hate having to set it every time they open Word. Is there a place to set this as their default view. Word2007. See http://word.mvps.org/FAQs/General/SaveViewAndZoom.htm -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "Rockitman" <Rockitman@discussions.microsoft.com> wrote in message news:0E262844-C0C0-49A8-97F6-065DE3637042@microsoft.com... >I have users who like the page width view but hate having to set it every > time they open Word. Is there a ...

Postcards not working
I created a blank postcard with 2 sides. It says each postcard is 1/4 of a page, but when I look at the print preview, only 2 per page show up. How do I get 4 postcards to appear on the page? I don't want to waste paper by printing only 2 per page? I have been trying everything I can think of and I can't figure it out! Help would be much appreciated!! In Publisher 2000 when you select File Print at the lower left corner of the Pint window is the "Page Options" button, select it. Now select the "Print multiple copies per sheet" Select the Custom Options butto...

lead primary attribute should allow company name or fullname
When viewing activities, it is essential for many users to see quickly what company they are concerned with, couldn't the fullname attribute for the lead be set to either the company name or one of the first and last name options. -- Marge in the uk ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I...

How to change the default datetime format for Windows Server 2003
As per the topic, I need to know how to change the default or the master datetime format for Windows 2003 Server Standard Edition. My problem is as such. One of my applications is working under the IIS, and thus getting the date and time from it. The IIS is running under local system and does not change the date time when I change if for the logged in user. Not even when I'm logged in as local administrator. My program take in dd/MM/yyyy but however it seems like the server is always default to M/d/yyyy or MM/dd/yyyy. So, how can i change the default setting so that it...

Default Opportunity views are ignoring closed state?
Hello, There are a number of 'system views' for opportunites like "Opportunities Closing Next Month" These views all seem to include already CLOSED opportunities, which does not make any sense! And, as system views, it does not appear I can 'fix' the filtering criteria. I can create new views that do what is expected, but this does not seem like valid behavior! Can I hide the system views? Am I doing something wrong? -- Len Ott Socket Communications ...

How to view a complete schema when using schema includes/imports?
I've got a parent schema file that references complex element types that are defined in several "child" schema files and I used the schema imports statement to include them into the parent schema's default namespace. I would like to generate a complete/single-file instance of the schema to simplify things but I can't figure out how to do it. Each schema seems to live in it's respective memory space inside the SchemaIncludesCollection. Any idea how I could traverse all of the "virtual" nodes in the parent schema to create a physical representation of what t...

how to declare an alias for a 2 dimensional array element?
Hi, I have an array below (in a very old piece of code): float (*fList)[6]; fList = new float[50][6]; .... My question is how to declare an alias for fList[10]: float &(p[6]) = fList[10]; float &p[6] = fList[10]; or ???? // The following is what I want to use p for. for (int i=0; i<6; i++) { p[i] /= 5.; } Please help. I know we should always avoid multi-dimensional array. Unfortunately, this is a very old piece of code. Thanks. Tony May Young wrote: >Hi, > >I have an array below (in a very old piece of code): > float (*fLis...

Outlook Archive: Not Working Properly
I have a Windows 2000 network with Exchange 2000 SP3. Recently, we've discovered that there is a "flaw" with multiple Outlook 2000/2002 client's ability to Archive messages via File>Archive. Here's the bottom line: 1) Outlook is only successful manually archiving [File>Archive...]) when you put in a date in the future (which of course moves all messages out of the Exchange folder and in to the archive PST). 2) When we try to use a past date when Archiving, the Outlook Archive process does appear to begin (activity in Outlook Status bar), but the end ...

product key not working with new computer
Setting up new computer and the product key code is not being recognized. I have installed everything else with no problems. When I got to ABOUT in the program the product id is blank. This is an upgrade version but I've installed Expression Web from upgrade version with no trouble. Is this a Publisher question or EW question? Expression is not a "upgrade" by the normal definition of "upgrade" - previous version is required. If your Publisher program IS an upgrade you will need a previous version or a qualifying product available prior to installing the upgrade...

Word 2007 automation
Hi I need to insert some HTML-styled text into a Word 2007 document. As far as I know you cannot directly insert HTML into Word, because it needs to be converted first. So I save the HTML as a temporary file and use InsertRange to insert it into my document. Here is my code: string TempFileSaveDir = "c:\\word"; private void InsertHTML(Document pDoc, string pHTML) { Guid _guid = Guid.NewGuid(); string _fileName = TempFileSaveDir + "\\" + _guid.ToString() + ".html"; TextWriter tw = new StreamWriter(_fileName, false, Encoding.UTF8); ...

Default Email Address View
How do I set the default email address to display the actual address and not the outlook defaul of the person's name? My address is nospam@nospam.com Outlook displays it as Staley, Greg I want the nospam@nospam.com to show. Greg What version of Outlook? --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. After searching google.groups.com and finding no answer: Greg <nospam@nospam.com> asked: | How do I set the default email address to display the actual address | and not the outlook defaul of the person's name? | | My address i...

Schema Mappings
Hi All, I have a couple of questions on Schema Mappings... I've setup CRM so that when an account is made the user has the option of choosing what added extras the client has. Examples of this are: Anti Virus, Anti Spam etc. I've set this up as a simple drop down menu on the account General tab. I want this drop down menu to link with another similar menu I've created under the case (incident) General tab. I'd like to set it up so that when you change one it effects the other (ie change accounts and it changes the case drop down. I tried mapping the schema fields to achiev...

security attribute properties
hi all, i have denied accidentally the read rights for "the authenticated user" in "all groups" subcontainer in "All address list" into exchange system manager. I'm not able to recover the error. I have tried "DSACLS.EXE" command, but the syntax is too much difficult for me. Can you help me to resolve this situation? Sorry for my bad english and thanks for all. Mauro Ooops... Have you tried to re-assign them using ADSIEDT? -- Jim McBee Blog - http://mostlyexchange.blogspot.com <alongsoul@tiscali.it> wrote in message news:1153929601...

Windows Live Mail and Adobe Photoship Elements 8
Is anyone using Live Mail and Adobe Photoshop Elements 8 without problems? Elements 7 does not recognise Live mail and although I have been assured by Adobe that Elements 8 is fully compatible with Windows 7 someone on an earlier thread reported a similar problem of not recognising Live Mail with Elements 8. Is there anyone out there who has sent photos by email from Elements 8 using Live Mail. I have put my order for 8 on hold pending further advice! Help would be much appreciated. "Gleaf2" <Gleaf2@discussions.microsoft.com> wrote in message news:C55A0B14-5...

The e-mail address in contacts is a hyperlink but it does not work
The e-mail address field in CRM is a hyperlink but it does not fire up outlook and put the e-mail address in. Is this our installation or does it not work for anybody? If anyone has got it working, do you know how? Thanks, Clare Clare, CRM 3.0 did not build in a double-click function to perform that action. What I have seen done to get around the issue is to add a JavaScript function on the contact (or account) onLoad event that adds this behavior. Here is a sample JavaScript to perform this action: var EmailHyperlink = function() { var emailAddress = crmForm.all.emailaddress1....

XML validate by XSD schema with C#
I am validating XML files on a server which has no internet access and the validadation in C# does not work. Schema with which I am validating has namespaces like: xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#". I have these schemas all locally on the disk, but it does not work. If I try on a computer with internet access then it works just fine. Does someone know what to do. Function with which I validate looks like this: private bool ValidXml(string XmlFile, string XSDLoc, string tns) { // . . . string targetNamespaceU...

Overriding default menu message handlers
Hi , I want to override the default message handlers for my app's menu items that have been provided by the MFC app wizard. e.g I want to execute my own code when File>New is clicked as well as call the default message handler for the File>New. How do I achieve it? Thanks in advance. Hi, when u create a mdi/sdi using mfc wizards by defaut for file->new cwinapps handler is called,u can see something like this "ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileNew)" in the cpp file of the class derived from CWinApp.Just modify this line and call ur own handler. ON_COMMAND(ID_F...

Schema Question
Hi, I am fairly new to XML schemas and why to use them. I am integrating with another application via xml. My questions are schemas only good to validate the XML documents or can I use the schema to help me parse the xml document? Thanks Well, following link will be useful to you. http://www.w3schools.com/schema/schema_why.asp ~ Ankit http://ankitjain.info/ankit/2006/07/01/forcing-download-on-web-page randy wrote: > Hi, > > I am fairly new to XML schemas and why to use them. I am integrating with > another application via xml. My questions are schemas only goo...

Command Button Stopped Working!!!!!!!
Greetings, I am using a CommandButton to run a procedure. This procedure was working fine, as was the CommandButton. Now, I cant seem to "see" the button (properties see's only the background sheet). When I make a new CommandButton, it will push down (the first would not even do that), but the properties still show the sheet not the button! Any ideas as to what is wrong and how to fix it? TIA -Minitman Does anyone have any suggestions as to which group I should post this question? TIA -Minitman On Mon, 21 Jun 2004 12:06:28 -0500, Minitman <exreply@i-m-pNOSPAM.net&...