XPath: Problem with inline elements

R

Rainer

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
 
R

Richard Tobin

Rainer said:
<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
 
Joined
Oct 13, 2008
Messages
2
Reaction score
0
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()
 

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

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top