473,508 Members | 2,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check wellformedness of XML

Is there a way (without a schema or dtd) to check that my XML (currently
held in a string variable) is wellformed? I've looked on google and in the
help files and couldn't find anything about this.
Thanks!

Tom S
Nov 16 '05 #1
2 11025
Hi Tom,

You can read the XML with XmlTextReader. To quote MSDN:

"The XmlTextReader class is an implementation of XmlReader, and provides a
fast, performant parser. It enforces the rules that XML must be well-formed.
It is neither a validating nor a non-validating parser since it does not
have DTD or schema information. It can read text in blocks, or read
characters from a stream."

And an example from another MSDN article to which I have added code to read
the whole contents of the XML stream.

string str = "<ROOT>AQID</ROOT>";
XmlTextReader r = new XmlTextReader(new StringReader(str));
try
{
while (r.Read())
{
}
}
finally
{
r.Close();
}

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Tom S" <no*****@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Is there a way (without a schema or dtd) to check that my XML (currently
held in a string variable) is wellformed? I've looked on google and in
the help files and couldn't find anything about this.
Thanks!

Tom S


Nov 16 '05 #2
Great, thanks!

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:eR**************@TK2MSFTNGP10.phx.gbl...
Hi Tom,

You can read the XML with XmlTextReader. To quote MSDN:

"The XmlTextReader class is an implementation of XmlReader, and provides a
fast, performant parser. It enforces the rules that XML must be
well-formed. It is neither a validating nor a non-validating parser since
it does not have DTD or schema information. It can read text in blocks, or
read characters from a stream."

And an example from another MSDN article to which I have added code to
read the whole contents of the XML stream.

string str = "<ROOT>AQID</ROOT>";
XmlTextReader r = new XmlTextReader(new StringReader(str));
try
{
while (r.Read())
{
}
}
finally
{
r.Close();
}

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Tom S" <no*****@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Is there a way (without a schema or dtd) to check that my XML (currently
held in a string variable) is wellformed? I've looked on google and in
the help files and couldn't find anything about this.
Thanks!

Tom S

Nov 16 '05 #3

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

Similar topics

17
4158
by: Craig Bailey | last post by:
Someone please explain what alternate universe I fell into this afternoon when PHP started telling me that 2 doesn't equal 2. Not sure about you, but when I run this, it tells me 59001.31 doesn't...
3
1563
by: indo3 | last post by:
Hello Is it right that a XML document is only wellformed if all entity references can be resolved in the document? this would mean that Xerces needs to retrieve external DTD files to get...
7
29845
by: Tony Johnson | last post by:
Can you make a check box very big? It seems like when you drag it bigger the little check is still the same size. Thank you, *** Sent via Developersdex http://www.developersdex.com ***...
2
27716
by: Travis.Box | last post by:
I have an MS Access userform with 16 Check Boxes. Each of the checkboxes has a different option value, which coincides with the Check Box name (eg. cb01.OptionValue = 1). At the bottom of the...
1
4244
by: scprosportsman | last post by:
Please help guys, i am trying to set up a database here at work and im fairly new to access in terms of writing functions and queries and stuff. I have 2 different places on my design that will...
2
3579
by: Chris Davoli | last post by:
How do you enable a check box in the GridView. I selected Checkbox Field in the Columns of the GridView, and the check box shows up in the Grid view, but it is disabled. How do I enable it so I can...
16
5631
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
5
11637
by: starke1120 | last post by:
Im creating a check in – check out database for RF guns. I have a table that contains models. ID (primary key) Model A table that contains Gun Details ID (primary key) Model_id...
19
107859
Frinavale
by: Frinavale | last post by:
Filtering user input is extremely important for web programming. If input is left unfiltered users can input malicious code that can cripple your website. This article will explain how to make...
0
7224
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
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7038
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
7493
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
5625
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,...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.