C#, Application, Problem with XML URI Prefix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahulrv
    New Member
    • Jun 2007
    • 1

    #1

    C#, Application, Problem with XML URI Prefix

    Hi,
    I have an xml which looks like this:

    <Events>
    <Event xmlns="http://abc.com">
    <System>
    <Name ="abc" />
    </System>
    <Manager>
    <Name ="abc1" />
    </System>
    </Event>
    </Events>

    I use the following code to obtain the System node and it fails

    XmlDocument document = new XmlDocument();
    document.Load(" c:\\results.xml ");

    XmlNodeList tmp1 = document.GetEle mentsByTagName( "Event");
    foreach (XmlNode k in tmp1)
    {
    XmlNode a = k.SelectSingleN ode("System");
    <<---------- a always returns NULL-------------->>
    << if I add a prefix to the URI, or remove the namespace URI from the results.xml, then it works, however, this is the XML i need to parse, any ideas. >>
    if (a != null)

    What am I doing wrong?

    Thanks,
    Rahul.
  • nandha8210
    New Member
    • Jun 2007
    • 2

    #2
    Rahul,

    i cant understand wy do u use foreach to get the System node
    Instead try using for loop iterating thru the nodelist

    try the following

    for(int i=0;i<tmp1.coun t,i++)
    {
    XmlNode a = tmp1[i].SelectSingleNo de("System");

    }

    now u get the system node in the XmlNode a

    hope this reply helps

    revert back if u hav any more queries

    cheers
    nandhu

    Comment

    Working...