XmlNamespaceManager.LookupPrefix problem.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Victor Hadianto

    #1

    XmlNamespaceManager.LookupPrefix problem.

    Hi All,

    I have the following code:

    <snip>
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml( @"<?xml version=""1.0"" encoding=""UTF-8""?>
    <myConfig:myCon fig xmlns:myConfig= ""http://mycomp/myConfig.xsd"">
    <myConfig:title >My Title</myConfig:title>
    </myConfig:myConf ig>");

    XmlNamespaceMan ager namespaceManage r = new
    XmlNamespaceMan ager(xmlDoc.Nam eTable);
    namespaceManage r.AddNamespace( "myConfig", "http://mycomp/myConfig.xsd");
    string prefix = namespaceManage r.LookupPrefix( "http://mycomp/myConfig.xsd");
    Console.WriteLi ne("Prefix is: " + prefix);
    </snip>

    What I am trying to do is to lookup the prefix for the namespace that I
    want. But ..this always returns null? What do I do wrong here?

    Thanks


  • Martin Honnen

    #2
    Re: XmlNamespaceMan ager.LookupPref ix problem.



    Victor Hadianto wrote:

    [color=blue]
    > I have the following code:
    >
    > <snip>
    > XmlDocument xmlDoc = new XmlDocument();
    > xmlDoc.LoadXml( @"<?xml version=""1.0"" encoding=""UTF-8""?>
    > <myConfig:myCon fig xmlns:myConfig= ""http://mycomp/myConfig.xsd"">
    > <myConfig:title >My Title</myConfig:title>
    > </myConfig:myConf ig>");
    >
    > XmlNamespaceMan ager namespaceManage r = new
    > XmlNamespaceMan ager(xmlDoc.Nam eTable);
    > namespaceManage r.AddNamespace( "myConfig", "http://mycomp/myConfig.xsd");
    > string prefix = namespaceManage r.LookupPrefix( "http://mycomp/myConfig.xsd");
    > Console.WriteLi ne("Prefix is: " + prefix);
    > </snip>
    >
    > What I am trying to do is to lookup the prefix for the namespace that I
    > want. But ..this always returns null? What do I do wrong here?[/color]

    You have to compare against the strings in the NameTable e.g.

    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml( @"<?xml version=""1.0"" encoding=""UTF-8""?>
    <myConfig:myCon fig xmlns:myConfig= ""http://mycomp/myConfig.xsd"">
    <myConfig:title >My Title</myConfig:title>
    </myConfig:myConf ig>");

    XmlNamespaceMan ager namespaceManage r = new
    XmlNamespaceMan ager(xmlDoc.Nam eTable);
    namespaceManage r.AddNamespace( "myConfig",
    "http://mycomp/myConfig.xsd");
    string prefix =
    namespaceManage r.LookupPrefix( xmlDoc.NameTabl e.Get("http://mycomp/myConfig.xsd")) ;
    Console.WriteLi ne("Prefix is: " + prefix);



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    Working...