Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: XML Validator Revisited ?

0 views
Skip to first unread message

Oleg Tkachenko [MVP]

unread,
Dec 15, 2004, 5:54:38 AM12/15/04
to
batham wrote:

> <Group ID="100">
> <Name>Dotnet XML</Name>
> <Member ID="BA1908">Guru Bhai</Member>
> </Group>
>
> When I validate this xml against a schema using XmlValidatingReader and
> when I get a error in the ID attribute of the Node Group, How can I get
> the Node or _FullName of that attribute.

XmlValidatingReader doesn't expose nodes. And you can get name of the
node it's positioned it via Name property.

> I cannot access _FullName which gives me the node name which is
> "Group", I get this error

Sure. It's private field.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

batham

unread,
Dec 15, 2004, 3:02:17 PM12/15/04
to
I know I can get the node name, but my problem is I want the parent
node

for eg.

if this was my XML file

<Books id="ab1"></Books>

and my schema validated this saying the ID is wrong which is a
attribute of BOOKS....... so when I get the error using
XmlValidatingReader, somehow I would like to know that the parent node
is BOOKS, which is stored in _FullName.

Thanks,
Shailendra Batham

batham

unread,
Dec 14, 2004, 7:54:23 PM12/14/04
to
Hello Gurus,

This is part of my XML File.

<Group ID="100">
<Name>Dotnet XML</Name>
<Member ID="BA1908">Guru Bhai</Member>
</Group>

When I validate this xml against a schema using XmlValidatingReader and
when I get a error in the ID attribute of the Node Group, How can I get
the Node or _FullName of that attribute.

I cannot access _FullName which gives me the node name which is


"Group", I get this error

'System.Xml.XmlValidatingReader._FullName' is inaccessible due to its
protection level

Is there a way I can get the Node Name to which the attribute belongs
to.

Thanks,
Shailendra Batham

Priya Lakshminarayanan [MSFT]

unread,
Dec 15, 2004, 5:05:43 PM12/15/04
to
If you want the element name while validating attributes store the name
before the first call to MoveToNextAttribute()
XmlValidatingReader valReader = new XmlValidatingReader(new
XmlTextReader("myxml.xml"));
while(valReader.Read()) {
if(valReader.NodeType == XmlNodeType.Element) {
string parentElementName = valReader.Name;
ProcessAttributes(parentElementName, valReader);
}
}

You can also call MoveToElement() when you encounter an error on an
attribute node and then get valReader.Name, but in this case you will have
maintain the postition of the attribute you are processing so that after
getting the element name, you have to reposition yourself on the same
attribute.

Thanks,
Priya

string parentElementName = val
"batham" <bat...@gmail.com> wrote in message
news:1103140937.0...@c13g2000cwb.googlegroups.com...

0 new messages