XPath: Problem with inline elements

Discussion in 'XML' started by Rainer, Oct 6, 2008.

  1. Rainer

    Rainer Guest

    Hello everybody,

    I have a question concerning XPath expressions. Consider this XML
    snippet:

    <foo title="an attempt">
    <ul>
    <li>This works fine</li>
    <li>Before the inline element <em>Inside the inline element</em> after
    the inline element</li>
    <li>This also works fine</li>
    </ul>
    </foo>

    In order to reach the first list element, I would use the XPath
    expression "/foo/ul/li[1]", which works fine. (I get the first list
    element with "This works fine", as expected.)

    However, I need an XPath expression that returns the second list
    element in three "portions":
    - "Before the inline element "
    - "Inside the inline element"
    - " after the inline element"

    I can get the inside of the inline element with "/foo/ul/li/em", but I
    have no idea how to get the surrounding strings. Any ideas?

    Kind regards,

    Rainer
    Rainer, Oct 6, 2008
    #1
    1. Advertising

  2. In article <>,
    Rainer <> wrote:

    ><li>Before the inline element <em>Inside the inline element</em> after
    >the inline element</li>


    >However, I need an XPath expression that returns the second list
    >element in three "portions":
    >- "Before the inline element "
    >- "Inside the inline element"
    >- " after the inline element"


    This will return the text descendants of the <li> elements:

    /foo/ul/li//text()

    -- Richard
    --
    Please remember to mention me / in tapes you leave behind.
    Richard Tobin, Oct 6, 2008
    #2
    1. Advertising

  3. Rainer

    Rainer Guest

    Hello Richard,

    Thank you very much, that seems to work!

    Kind regards,

    Rainer
    Rainer, Oct 6, 2008
    #3
  4. Rainer

    nathyx

    Joined:
    Oct 13, 2008
    Messages:
    2
    Hello Guys, i need help with my project, i created a web blog as part of my project, when i run it, it return this error that i have done i could but still to no avail. Please someone help relieve the pain. I am using V.S 2003 C# Asp.Net

    i followed the book and checked over and over again all is correct, my xml displays in the IE with no error, i can even add xml files into the folder i created to store the xml files called Entries. But i still get the below error message.

    Below is the error message

    The data at the root level is invalid. Line 1, position 1.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Xml.XmlException: The data at the root level is invalid. Line 1, position 1.

    Source Error:


    Line 81: FileStream file = new FileStream(filepath, FileMode.Open);
    Line 82: XmlSerializer serializer = new XmlSerializer(typeof(Entry));
    Line 83: Entry newEntry = (Entry)serializer.Deserialize(file);
    Line 84: file.Close();
    Line 85: newEntry.Timestamp = new FileInfo(filepath).LastWriteTime;


    Source File: c:\inetpub\wwwroot\hotelweb\global.asax.cs Line: 83

    Stack Trace:


    [XmlException: The data at the root level is invalid. Line 1, position 1.]
    System.Xml.XmlTextReader.ParseRoot() +295
    System.Xml.XmlTextReader.Read() +127
    System.Xml.XmlReader.MoveToContent() +75
    Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read4_Entry() +16

    [InvalidOperationException: There is an error in XML document (0, 0).]
    System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
    System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, XmlDeserializationEvents events)
    System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)
    HotelWeb.Global.LoadEntry(String filename) in c:\inetpub\wwwroot\hotelweb\global.asax.cs:83
    HotelWeb.Global.LoadAllEntries() in c:\inetpub\wwwroot\hotelweb\global.asax.cs:97
    HotelWeb.HotelWebLog.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\hotelweb\hotelweblog.aspx.cs:31
    System.Web.UI.Control.OnLoad(EventArgs e)
    System.Web.UI.Control.LoadRecursive()
    System.Web.UI.Page.ProcessRequestMain()
    nathyx, Oct 13, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alastair Cameron
    Replies:
    1
    Views:
    7,364
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  2. Abhi
    Replies:
    2
    Views:
    725
    E. Robert Tisdale
    Jul 3, 2003
  3. Alvin
    Replies:
    7
    Views:
    464
    E. Robert Tisdale
    May 6, 2005
  4. Replies:
    3
    Views:
    447
  5. Rach
    Replies:
    1
    Views:
    451
    Andy Dingley
    May 17, 2006
Loading...

Share This Page