parseing an xml string

K

Keith Henderson

I have an xml document loaded into a string that I need to parse. below is
the first few elements in the xml string.

<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerShortName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="CreateDate" type="xs:dateTime" />
.... there is more I didn't show......


I need to step through it and if you look closely you see 2 keys
identifying column names, CustomerShortName and CreateDate

they are defined as
<xs:element name="CustomerShortName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10" />
</xs:restriction>
</xs:simpleType>
</xs:element>

and

<xs:element name="CreateDate" type="xs:dateTime" />


I need to step through the entire xml document and retrieve out
CustomerShortName, string, 10
and
CreateDate, dateTime

can someone show me how to parse this?
 
C

CJ Taylor

If you need to "step through" XML you should use an SAX Parser. DOM Parsers
read in the entire document and then allow you to parse, SAX will actually
raise events for elements being read/parsed.

There is a free SAX Parser that comes with the Visual Basic Resource Kit I
believe.

-CJ
 
T

Tom Shelton

I have an xml document loaded into a string that I need to parse. below is
the first few elements in the xml string.

<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerShortName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="CreateDate" type="xs:dateTime" />
.... there is more I didn't show......


I need to step through it and if you look closely you see 2 keys
identifying column names, CustomerShortName and CreateDate

they are defined as
<xs:element name="CustomerShortName">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10" />
</xs:restriction>
</xs:simpleType>
</xs:element>

and

<xs:element name="CreateDate" type="xs:dateTime" />


I need to step through the entire xml document and retrieve out
CustomerShortName, string, 10
and
CreateDate, dateTime

can someone show me how to parse this?

You'll probably want to look at the documentation and example for
System.Xml.XmlTextReader....
 
T

Tom Shelton

If you need to "step through" XML you should use an SAX Parser. DOM Parsers
read in the entire document and then allow you to parse, SAX will actually
raise events for elements being read/parsed.

There is a free SAX Parser that comes with the Visual Basic Resource Kit I
believe.

-CJ

I think that XmlTextReader meets these requirements...

from the docs:

XmlTextReader Class
Represents a reader that provides fast, NON-CACHED, forward-only access
to XML data.

I don't think he really needs the resource kit....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top