473,503 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Validate the XML file

S


Hi,
I have the following xml file

<?xml version="1.0" encoding="UTF-8" ?>
<n1:Message xmlns:n1="nz:govt:moh:schemas:diabetes-cardio.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MessageHeader>
<Site>pho1diab</Site>
<SendingApplication>MyPracticePMS 8.05a</SendingApplication>
<SendingFacility>PracticeName or HeathLinkMailBox</SendingFacility>
<ReceivingApplication>Diabetes/CVD v2</ReceivingApplication>
<ReceivingFacility>pho1diab</ReceivingFacility>
<CreationDateTime>20060424132630</CreationDateTime>
<MessageType>DBT_DAT</MessageType>
<MessageSpecificationVersion>002</MessageSpecificationVersion >
<MessageID>message 123456</MessageID >
<ProcessingID>P</ProcessingID >
<OtherParameters>OtherParameters go here</OtherParameters>
</MessageHeader>
and the following xsd file as

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="Message">
<xs:complexType>
<xs:sequence>
<xs:element name="MessageHeader" type="MessageHeaderType"/>
<xs:element name="MessageBody" type="MessageBodyType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="MessageHeaderType">
<xs:sequence>
<xs:element name="SendingApplication">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="SendingFacility">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="ReceivingApplication" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="ReceivingFacility">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="CreationDateTime" type="xs:dateTime"/>
<xs:element name="MessageID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="MessageType" type="MessageTypeType"
fixed="CVD_DAT"/>
<xs:element name="ProcessingID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MessageTypeType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="Version" type="xs:string" use="required"
fixed="2.0"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
How to validate each text contained in the xml file against the xsd
file i.e the data type each text should be correct as well as to check
each required attribute is present or not. can anybody suggest me the
solution

*** Sent via Developersdex http://www.developersdex.com ***
Dec 1 '06 #1
1 1795
S wrote:
How to validate each text contained in the xml file against the xsd
file i.e the data type each text should be correct as well as to check
each required attribute is present or not. can anybody suggest me the
solution
Generally with the .NET framework and XML (which this newsgroup is
about) to validate with .NET 1.x you need to use an XmlValidatingReader,
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlValidatingReaderClassTopic.asp>
with .NET 2.0 you need to use an XmlReader with the proper
XmlReaderSettings to do validation:
<http://msdn2.microsoft.com/en-us/library/system.xml.xmlreadersettings.aspx>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Dec 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3150
by: Ray Tayek | last post by:
hi, fooling around with xmlspy (which seems pretty broken when *doing* xslt's). trying to validate in java using code from http://cermics.enpc.fr/doc/java/j2eetutorial-1.4/doc/JAXPSAX13.html...
0
1566
by: Aaron P Frenger | last post by:
Hello All, I have a very large XML file that I would like to split up into a few smaller files, but still use only one schema. I am using Xerces C++ libraries. My idea is to have one schema...
8
3091
by: Dean Speir | last post by:
Hi... I've been referred to this Newsgroup by the W3C Markup Validator FAQ. I've been happily using this Validator <http://validator.w3.org> for the past 18 months with great success, but...
9
2918
by: Rob Mayo | last post by:
I have a bunch of XSD files in my assembly as embedded content that are read out via reflection and streams. My app creates the XML on the fly, and I want to validate it using the schema files...
1
9086
by: aevans1108 | last post by:
Greetings All If this is the wrong place to post this question, please give me a push in the right direction. Thanks. I know there has to be a simpler way to do this, but this is as simple a...
0
4562
by: SHC | last post by:
Hi all, I have a VC++ .NET 2003 - Windows XP Pro PC. I created a Win32 console application in my VC++ .NET 2003 and copied validateDOM.cpp, books.xml and books.xsd (see the attached files below)...
7
16216
by: Ali-R | last post by:
Hi all, I am getting a CSV file like this from our client: "C1","2","12344","Mr","John","Chan","05/07/1976"......... I need to validate **each filed value** against a set of rules ,for...
4
10586
by: Mr. x | last post by:
Hello, I know about the validator on : http://validator.w3.org , which can validate html pages. I just new to this validator. How can I validate (if it can be - by this validator) aspx pages,...
6
2741
by: Jonny | last post by:
Hi, I'm trying to validate my xml against a xsd but I can't get it to work. Originally, I wanted to validate an xml string but since I didn't get that to work I tried to validate an xml file...
0
2631
by: Marc Scheuner | last post by:
Folks, I'm faced with a dilemma here - I have an XML document and for part of it, I have an XSD schema to validate it - but not for the rest of it. Can I still validate at least part of the...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7458
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.