Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7969927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:18:55+00:00 2026-06-04T07:18:55+00:00

I have the following xml: <?xml version=1.0?> <catalog> <book id=bk101> <author>Gambardella, Matthew</author> <title>XML Developer’s

  • 0

I have the following xml:

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
</catalog>

I found the title named “Midnight Rain”. Now i want to know who is his parent so that i can use the <author> text node. I tried something like:

  var xpath = "../*[local-name() != 'title']";
       xml.Load(xmlalltext);
       var xl1 = xml.SelectNodes(xpath);
       MessageBox.Show(xl1.Item(0).InnerText.ToString());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:18:56+00:00Added an answer on June 4, 2026 at 7:18 am

    If you’ve already found the title node and you’re looking for the parent node, you can just select the parent node of the current node.

    var parentNode = titleNode.SelectSingleNode("..");
    

    If you’re looking for the author node:

    var authorNode = titleNode.SelectSingleNode("../author");
    

    Alternatively, you may look for preceding or following siblings:

    var authorNode = titleNode.SelectSingleNode("following-sibling::author") ?? titleNode.SelectSingleNode("preceding-sibling::author");
    

    Edit: To answer your comment, if you only have the string of the title, then you may use the following to get the author:

    string xml = @"xml...";
    var doc = XDocument.Parse(xml);
    string author = doc
        .Descendants("book")
        .Where(x => x.Element("title").Value == "Midnight Rain")
        .Select(x => x.Element("author").Value)
        .FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

say, i have such xml file: <?xml version=1.0?> <catalog> <title>My book catalog</title> <link>http://example.com/catalog</link> <book
Consider the following XML: <?xml version=1.0 encoding=ISO-8859-1?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY>
I have an XML file looks like the following <?xml version=1.0 encoding=ISO-8859-1?> <CATALOG> <food>
Following is sample XML File - <?xml version=1.0 encoding=UTF-8?> <Catalog> <Book> <AName>Steven Holzner</AName> <BName>Using
I have the following XML <?xml version=1.0 encoding=ISO-8859-1 ?> - <DEVICEMESSAGES> <VERSION xml=1 checksum=
I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
I have the following simplified XML: <?xml version="1.0" encoding="UTF-8" ?> <MATMAS05> <IDOC BEGIN="1"> <E1MARAM
I have the following simplified XML structure: <?xml version="1.0" encoding="UTF-8" ?> <INVOIC02> <IDOC BEGIN="1">
I have following xml file: <?xml version = "1.0" ?> <Employee> <Emp_Id>E-001</Emp_Id> <Emp_Name>Vinod</Emp_Name> <Emp_E-mail>Vinod1@yahoo.com</Emp_E-mail>
Let's say I have following Spring config (version of Spring is 3.0.3): <?xml version=1.0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.