Validating Xml Fragments .NET 2.0

I was wondering if someone would help me with validating specific
parts of an xml document again its XSD.
I would like to valiate the a fragment


<property name="TextMode">Multiline</property>

The error I get when validating with validate method of XmlDocument
is

    Validation Error: The 'http://www.w3schools.com:property' element
is not declared.

Here's the code,

        Dim ReaderSettings As XmlReaderSettings
        Dim NameSpaceMgr As XmlNamespaceManager
        Dim ParserContext As XmlParserContext
        Dim XmlString As String = "<property>Value</property>"
        Dim XmlBuffer As New StringReader(XmlString)
        Dim XmlDoc As XmlDocument

        ReaderSettings = New XmlReaderSettings()
        ReaderSettings.Schemas.Add("http://www.w3schools.com", "C:
\projects\hsn\Tests\Questionnaire.xsd")
        ReaderSettings.ValidationType = ValidationType.Schema
        ReaderSettings.ValidationFlags =
Schema.XmlSchemaValidationFlags.ReportValidationWarnings
        AddHandler ReaderSettings.ValidationEventHandler, AddressOf
ValidationCallback

        ReaderSettings.ConformanceLevel = ConformanceLevel.Fragment

        ReaderSettings.NameTable = New NameTable()
        NameSpaceMgr = New
XmlNamespaceManager(ReaderSettings.NameTable)
        NameSpaceMgr.AddNamespace("", "http://www.w3schools.com")

        XmlDoc = New XmlDocument()



        ParserContext = New XmlParserContext(ReaderSettings.NameTable,
NameSpaceMgr, "en", XmlSpace.Default)


        XmlDoc.Load(XmlReader.Create(XmlBuffer, ReaderSettings,
ParserContext))
        XmlDoc.Validate(New ValidationEventHandler(AddressOf
ValidationCallback))


Cheers,
Aeden

0
8/7/2007 4:42:05 AM
dotnet.xml 7266 articles. 0 followers. Follow

5 Replies
393 Views

Similar Articles

[PageSpeed] 51

aeden.jameson@gmail.com wrote:
> I was wondering if someone would help me with validating specific
> parts of an xml document again its XSD.

>         ReaderSettings.Schemas.Add("http://www.w3schools.com", "C:
> \projects\hsn\Tests\Questionnaire.xsd")

Can you show us the XSD schema?




-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
8/7/2007 2:46:47 PM
On Aug 7, 7:46 am, Martin Honnen <mahotr...@yahoo.de> wrote:
> aeden.jame...@gmail.com wrote:
> > I was wondering if someone would help me with validating specific
> > parts of an xml document again its XSD.
> >         ReaderSettings.Schemas.Add("http://www.w3schools.com", "C:
> > \projects\hsn\Tests\Questionnaire.xsd")
>
> Can you show us the XSD schema?
>
> --
>
>         Martin Honnen --- MVP XML
>        http://JavaScript.FAQTs.com/

The XSD is


<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://
www.w3schools.com" xmlns:NS="http://www.w3schools.com"
targetNamespace="http://www.w3schools.com"
elementFormDefault="qualified">
  <xs:element name="questionnaire">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="element" minOccurs="1">
          <xs:complexType mixed="true">
            <xs:sequence>
              <xs:element name="property" minOccurs="0"
nillable="false">
                <xs:complexType mixed="true">
                  <xs:simpleContent>
                    <xs:extension base="xs:string">
                      <xs:attribute name="name" type="xs:string"
use="required" />
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
              <xs:element name="option" minOccurs="0">
                <xs:complexType mixed="true">
                  <xs:simpleContent>
                    <xs:extension base="xs:string">
                      <xs:attribute name="value" type="xs:string"
use="required" />
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="id" type="id-type" use="required" />
            <xs:attribute name="element-type" type="element-types"
use="required" />
            <xs:attribute name="control-type" type="xs:string"
use="required" />
            <xs:attribute name="order" type="xs:int" use="required" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="title" type="xs:string" use="required" />
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="element-types">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Question" />
      <xs:enumeration value="TextElement" />
      <xs:enumeration value="Validator" />
    </xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="id-type">
    <xs:restriction base="xs:string">
      <xs:pattern value="HSNQ_\d+" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

0
8/7/2007 5:57:18 PM
aeden.jameson@gmail.com wrote:

> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://
> www.w3schools.com" xmlns:NS="http://www.w3schools.com"
> targetNamespace="http://www.w3schools.com"
> elementFormDefault="qualified">
>   <xs:element name="questionnaire">

So the root element name the schema defines is questionnaire while you 
are trying to validate against an element named property which should be 
a descendant element. That is why you get that error message, the XML 
parser looks at the schema and does not find a (top-level) definition 
for the property element.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
8/8/2007 1:50:29 PM
So there's no way to inform XmlDocument.Validate through the
readersettings or some other object to only use a specific part of the
document?

As an aside, I want to require the property element have text. How do
I do that?

On Aug 8, 6:50 am, Martin Honnen <mahotr...@yahoo.de> wrote:
> aeden.jame...@gmail.com wrote:
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://
> >www.w3schools.com" xmlns:NS="http://www.w3schools.com"
> > targetNamespace="http://www.w3schools.com"
> > elementFormDefault="qualified">
> >   <xs:element name="questionnaire">
>
> So the root element name the schema defines is questionnaire while you
> are trying to validate against an element named property which should be
> a descendant element. That is why you get that error message, the XML
> parser looks at the schema and does not find a (top-level) definition
> for the property element.
>
> --
>
>         Martin Honnen --- MVP XML
>        http://JavaScript.FAQTs.com/


So there's now way to

0
8/9/2007 8:55:24 PM
aeden.jameson@gmail.com wrote:
> So there's no way to inform XmlDocument.Validate through the
> readersettings or some other object to only use a specific part of the
> document?

The Validate method has an overload where you can pass in an XmlNode, 
that way you can try to validate a subtree. But it has to sit in the 
complete document at the right position, I don't think you can simply 
pass in an arbitrary fragment.

> As an aside, I want to require the property element have text. How do
> I do that?

What exactly do you want to require? That the content of the property 
element is simple text with no elements? You can do that as follows:

   <xs:element name="property">
     <xs:complexType>
       <xs:simpleContent>
         <xs:extension base="xs:string">
           <xs:attribute name="name" type="xs:string" use="required"/>
         </xs:extension>
       </xs:simpleContent>
     </xs:complexType>
   </xs:element>

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
8/10/2007 2:01:03 PM
Reply:

Similar Artilces:

Back-up to CD #2
Does the Money 2004 Standard Edition or Premium Edition have hte ability to back-up to a CD (versus a floppy diskette)? Only if packet writing software, such as Direct CD, makes the CD appear to be a regular read-write file system. Can Notepad save a file to your CD? If so, Money should work too. But Money does nothing to prevent you from burning your data file to CD just like you burn any other data file. "Suzi V" <anonymous@discussions.microsoft.com> wrote in message news:b88901c48946$26689280$a501280a@phx.gbl... > Does the Money 2004 Standard Edition or Premium Editi...

Msgbox entry validation
The following Macro will not loop more than twice the error entries. Will someone help me correct it to loop indefinely? Thanks Sub Entry_validation() Dim Teststring As String Dim Inputstring As String Cells(1, 1) = "ABC" 'as given filename Cells(2, 1) = "DEF" 'as given filename Cells(3, 1) = "GHI" 'as given filename Cells(4, 1) = "JKL" 'as given filename errorloop: Inputstring = InputBox(prompt:="Enter Filename" & vbLf & "Enter abort to abort en...

Credit Card Processors #2
I am in the process of acquiring RMS but I am not sure yet... at the same time I have to choose a credit card processor. I wanted to go with Citibank as all the credit card interfaces are built in and I don't want to sign on with a company that gives me a 24 month equipment contract because that just makes it a hassle to integrate with RMS later and pay rental fee for equipment I don't use. Anyone have any recommendations? i spoke to Citi and they gave me a rate of 1.71 which is okay but do they do check verification? and gift cards? Does anyone get a lower rate then 1.71 from Citi? I ...

Data Validation -> Validation list is larger than the cell width
I have a workbook that I've just added data validation to one cell. FWIW, the data validation is based on a named range. Here's the (perceived) problem. When I've set up data validation in the past, the selection is the same width as the cell. In this case, the list starts almost a full cell width to the left. What am I missing? Thanks, Barb Reinhardt Barb, In Excel2003 I can replicate what you describe under the following conditions: 1. the named range contains entries that are wider than the data validation cell 2. The data validation cell is r...

Can Publisher 2007 produce the same cool picture effects as Word 2
In Word 2007, there are some really cool new picture effects such as * blurred edges, * an effect that looks like an actual photograph with white edge (with or without tilt) raised off the page with a shadow, * reflection shadows, * etc. I had Publisher 2003, which could not do these effects natively and furthermore wouldn't even correctly print an image effect I created in Word 2007 and then copy/pasted into Pub 2003. So I bought the Pub 2007 upgrade and I still can't figure out how to do it. I need to figure this out quickly because if I can't get it to...

Parsing XML in string variable?
I have a method that returns a string that contains XML, and I need to parse that string (ie. find specific keys). How can I do this? I found one that searches a Stream, but I don't know how to convert from string to stream. Thanks. hi vmi, you could use the System.Xml.XmlDocument class, simply make a new instance and use the LoadXml-Method (does not properly load string with encoding markers). You could also use the .NET 3.5 System.Xml.Linq.XElement. There are several utility classes to read from strings and streams and vice versa, e.g. System.IO.StringReader &am...

Microsoft Word 6.0/95 Documents Not Opening in
Version: 2004 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Two recent strange occurrences: <br><br>1)Older documents originally created with Microsoft Word 6.0/95 are not opening in Microsoft Word 2004 for Mac (ver. 11.5.6) even though within their preview (next column over from actual file/document) it says that the document was modified and last opened when the document attempted to open, but actually never appeared. <br><br>2)Some kind of font formatting within even newer, recently created Microsoft Word 2004 documents has changed. Most docum...

Insert XML string into XML File: Part 2
Thanks to some good help from a previous post, I have been able to create well formed xml as part of a report logger app. However, I still have a small problem. When I add new xml to the log file, the new nodes are appended to the original file. What I really want is for the log file to grow as "report nodes" are added. Also, I am a bit concerned about performance, particularly as the file grows in size. I must write to an xml file (vs. a database) and am trying to understand the best way to do this. I prefer to not use "temp files" and would like to just modify the ...

Split Transactions #2
The new system will not show my stocks that have had a split transaction. Is there any way to resolve this? Can I reenter the stocks as new? On Mon, 9 Nov 2009 10:31:01 -0800, Fergie <Fergie@discussions.microsoft.com> wrote: >The new system will not show my stocks that have had a split transaction. Is >there any way to resolve this? Can I reenter the stocks as new? And what would the new system be? ...

MSCRM with .net framework
We want to install MSCRM server and VC++.net on the same machine. There is a conflict in the .net framework. How do I overcome this. I get error in MSCRM when I install .netframework shipped with VC. Is there a service pack to handle this are you using VS.net studio 2003 the you need to install .Net framework 1.1, ..net framework 1.0+vs.net2002 is the the combination no problem with 1.0 and 1.1 side by side installtion. mscrm works with 1.0 and vc.net works with 1.1 you already installed vs.net and while opening MSCRM its giving error?if yes please specify the error. please expal...

XLS to CSV file in notepad #2
Thanks, I see if that works -- lmk00 ----------------------------------------------------------------------- lmk001's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1000 View this thread: http://www.excelforum.com/showthread.php?threadid=26901 ...

Incorrect Password #2
My PC crashed and I've had to restore all applications and files. I've reinstalled Money 2002, but when I try to open my last Money file and enter the correct password, I receive a message that the password I entered is incorrect. I've used the same password for years, so I know I'm entering the right password. I also used Microsoft Passport with Money. What do I need to need to fix this problem? Is there something else I need to do to restore Money? I have years of Money data at stake. Thanks for your help. In microsoft.public.money, Bobcat wrote: >My PC crash...

R1C1 reference style #2
I know how to get rid of it now - maybe not permanently, it seems to come back as a default at times. But does anyone know what it's actaully used for? Tools|options|General Tab|check/uncheck R1C1 Reference style. Believe it or not, some people like working this way! (It is a nice way to compare formulas that should be the same, though.) And excel picks it up from the first workbook you opened that session. You may just be unlucky enough to open a workbook that was saved (by someone else???) in R1C1 reference style. Peg P wrote: > > I know how to get rid of it now - maybe ...

Validating against a DTD
Hello All, I am trying to validate an xml file against a DTD. I went through a lot of examples especially: http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank/System_Xml/XmlValidatingReader/Validator/validator.src&file=validator.cs&font=3 but its not working in my case. First of all, when i try to add my DTD file in XmlSchemaCollection object, it throws an error saying DocType element is expected. I am using NITF DTD for this and there is no DocType element in it. Any help will be appreciated. Thanks. VD You should not add DTDs to XmlSchemaCollection. XmlSchema...

Only 36 more days 2 go until the mentally ill Kevin Panzke finishes this round of Ubuntu countdown for Alpha3! Just FYI!
Just FYI. ...

Convert #N/A to 0
Hi, I have a formula that returns #N/A in some cells. I want to be able to convert the #N/A cells to the value 0. I have tried using the ERROR.TYPE formula in an IF function and it converts #N/A cells to 0, however, it also converts the non-#N/A cells to #N/A. I need to keep the value in the non-#N/A cells. According to the help file for this function, I should be able to have the value in the cell returned if it is a false statement. Ex. IF(ERROR.TYPE(E8)=7),0,E8) If E8 = 100, this formula should return 100 and not #N/A for that cell. Any assistance would be greatly appreciated...

XML Tree Structure
Hi Folks, I would like to take a XML document and write its data into a tree structure for a custom tree control. The document has two fields with one called task (a text field) and the other called tree_level (an integer field). Consider the document to be valid and well-formed. The tree_level is an index describing where a node will reside in a tree structure. A partial view of the XML document is as follows: <task>summary task</task> <tree_level>0</tree_level> <task>task1</task> <tree_level>1</tree_level> <task>task2</task&...

Validation dropdown list is not coming visible
Hi, I'm using XP and 2003. I have a problem that I have once found resolution, but now it came again and cannot remember what needs to be done. Here is the problem: There is a column where Validation is specified in right manner with error message in case of error. When selecting the cell - dropdown list is not coming visible. In case I write something wrong it gives error message. If I recall correctly - it was something to do with some kind of list. How can I change this to work properly? I tried to paste new column from another file where the column is working as I want...

Convert blanks to 0 in report
I have a table with the following entries Totals salesoffice Type 319655.46 200 Cash Contribution 2607.94 200 Cash Distribution 1078475.47 200 Security Contribution 1369438.83 300 Cash Contribution 43347.03 300 Cash Distribution 1080221.3 300 Security Contribution 47362.84 300 Security Distribution I'm using a Cross-Tab query as the source for a report. The query is TRANSFORM Sum([Contributions & Distributions Totals].Totals) AS SumOfTotals S...

dynamic array #2
Hi you clever peeps! What's the best way to pass a dynamic array from one dialog to another? let me clarify. I'm quite new to C++ so, be nice :-( I have a class CReference, which is an CObArray object. One of the CReference variable is "category", which is a CString object. Since more than one CReference object can belong to the same category, the size of category is not necessarily the same as the size of CReference Object Array. So I've written a crude routinte that creates a dynamic array m_daCat, that goes thru every CReference object and add its category to m_daC...

Jobs in MS CRM 3.0
Hello, I see two jobs in SqlServer. 1.MSCRM Stored Procedure Priming 2.Start_Incremental on Allianz_MSCRM.ftcat_documentindex.[7.5] This jobs runs every 10 minutes or 15 minutes. Does this jobs need to run during those times? Is possible to start up this more rarely? thanks for replay Andrej You can reduce the interval on the first one w/o drastic side effects. It's purose is just to ensure that the procedures that are used for some of the cascading logic are compiled and kept in the code cache in SQL. The second one though affects how KBase searching works. This is what update...

Data Validation
Hi all I want to set data validation on a cell so that it will accept the following (and only the following) text strings: (1) "BR" (literally) or (2) "NT" (literally) or (3) "nA" where n is any positive integral numerical value including zero and A may take any of the values "L", "P", "T", "V" or "Y" or (4) "An" where n is any positive integral numerical value including zero and A may take either of the values "K" or "D". Is this possible, please, and if so how? thanks -- Return e...

.NET application won't run on Win2k
I've recently ported my application from VC++6 to VC++.NET and find that it no longer runs on Win2k. How do I resolve this? The error I get when I try to run it is "The dynamic link library MFC71U.DLL could not be found in the specified path C:\Prog..." Fair enough I thought: I'm linking against MFC 7.1 instead of 4.x and I need to distribute the DLL. Except that MFC71U.DLL doesn't exist on my WinXP build machine either so I can't distribute it. So I tried statically linking to it instead and got lots errors of the form "error LNK2005: _wcscmp already defined ...

Z Report ? #2
Can some be so kind as to expalin to me the proper way to do a Z Report. 1) Enter the opening amount at the start of the day 2) Enter closing amounts at the end of the day (Now what is this amount, the amount that is kept in the till or the amount you count for the day?) 3) Finally, print a z report Thanks in advance What we do and you can modify however you need is the following: We count the draw open.(for us a set opening amount) At closing we count it again entering everything in the drawer. After this initial count we run an X report. X reports allow you to change closing informat...

[ANN] Liquid XML Studio Released
Announcing the release of Liquid XML Studio 2008 a Freeware XML Development Environment. Download available from www.liquid-technologies.com. Key features include - An Advanced Graphical Schema Editor - XML Editor, with auto-complete, syntax highlighting & validation - Web Service Browser, supports calling Soap services - XPath Expression Builder, visualise XPath expressions - Documentation Generator, HTML Docs from your XML schemas - Code Generation, C++, C#, .Net, Java, VB .Net & VB6 (trial) Liquid XML...XML the smart way! ...