XpathNavigator.MovetoId()

M

Michael Soza

Hi all, I need a little help with the use of that method. I have an xml of
this kind:
<?xml version="1.0"?>
<!DOCTYPE raiz[
<!ELEMENT raiz (docu,code)>
<!ELEMENT docu (#PCDATA)>
<!ELEMENT code (#PCDATA)>
<!ATTLIST docu ID ID #REQUIRED>
<!ATTLIST code ID ID #REQUIRED>
<!ATTLIST code Name CDATA #REQUIRED>
]>
<raiz>
<docu ID="a">hola</docu>
<code ID="b" Name="Tierra">Mundo</code>
</raiz>


when I search elements with tag docu works : navigator.MoveToId("a")->true
when I search elements with tag code doesn't work :
navigator.MoveToId("b")->false

the cuestion is WHY?????
 
M

Martin Honnen

Michael said:
Hi all, I need a little help with the use of that method. I have an xml
of this kind:
<?xml version="1.0"?>
<!DOCTYPE raiz[
<!ELEMENT raiz (docu,code)>
<!ELEMENT docu (#PCDATA)>
<!ELEMENT code (#PCDATA)>
<!ATTLIST docu ID ID #REQUIRED>
<!ATTLIST code ID ID #REQUIRED>
<!ATTLIST code Name CDATA #REQUIRED>
]>
<raiz>
<docu ID="a">hola</docu>
<code ID="b" Name="Tierra">Mundo</code>
</raiz>


when I search elements with tag docu works : navigator.MoveToId("a")->true
when I search elements with tag code doesn't work :
navigator.MoveToId("b")->false

the cuestion is WHY?????

I can reproduce the problem with Visual Studio 2008 SP 1/.NET 3.5 SP 1.
Test code is as follows:

XPathDocument doc = new XPathDocument(@"..\..\XMLFile1.xml");
XPathNavigator nav = doc.CreateNavigator();
if (nav.MoveToId("b"))
{
Console.WriteLine("Found {0}.", nav.OuterXml);
}
if (nav.MoveToId("a"))
{
Console.WriteLine("Found {0}.", nav.OuterXml);
}

Output is fine:

Found <code ID="b" Name="Tierra">Mundo</code>.
Found <docu ID="a">hola</docu>.


Are you sure you are running your code against the XML you posted?
 
M

Michael Soza

I fix the problem.....what I need was something like this.....
Inside <raiz> elements <code> or <docu> in any order and any number
Inside<code> text or more <code> or <docu> in any order and any number
and for <docu> only text inside..
So the dtd I was defined was incorrect and works for the example I posted
but not for the real xml that I needit to work....and for that reason the
MoveToId method behaves strange.
Finally the dtd was like this:

<!ELEMENT raiz (docu|Code)*>
<!ELEMENT docu (#PCDATA)>
<!ELEMENT Code (#PCDATA|docu|Code)*>
<!ATTLIST docu ID ID #REQUIRED>
<!ATTLIST Code ID ID #REQUIRED>
<!ATTLIST Code Name CDATA #REQUIRED>


MoveToID works like a charm, :).
Thanks Martin.


Martin Honnen said:
Michael said:
Hi all, I need a little help with the use of that method. I have an xml
of this kind:
<?xml version="1.0"?>
<!DOCTYPE raiz[
<!ELEMENT raiz (docu,code)>
<!ELEMENT docu (#PCDATA)>
<!ELEMENT code (#PCDATA)>
<!ATTLIST docu ID ID #REQUIRED>
<!ATTLIST code ID ID #REQUIRED>
<!ATTLIST code Name CDATA #REQUIRED>
]>
<raiz>
<docu ID="a">hola</docu>
<code ID="b" Name="Tierra">Mundo</code>
</raiz>


when I search elements with tag docu works :
navigator.MoveToId("a")->true
when I search elements with tag code doesn't work :
navigator.MoveToId("b")->false

the cuestion is WHY?????

I can reproduce the problem with Visual Studio 2008 SP 1/.NET 3.5 SP 1.
Test code is as follows:

XPathDocument doc = new XPathDocument(@"..\..\XMLFile1.xml");
XPathNavigator nav = doc.CreateNavigator();
if (nav.MoveToId("b"))
{
Console.WriteLine("Found {0}.", nav.OuterXml);
}
if (nav.MoveToId("a"))
{
Console.WriteLine("Found {0}.", nav.OuterXml);
}

Output is fine:

Found <code ID="b" Name="Tierra">Mundo</code>.
Found <docu ID="a">hola</docu>.


Are you sure you are running your code against the XML you posted?
 

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