How to add a child element to the Pages xml files?

Topics: ASP.NET 2.0
Oct 30, 2010 at 10:10 AM
Edited Oct 24, 2011 at 4:57 PM

Current xml pages are:

<page>
  <title>Testing Page Name This is Title</title>
  <description>Main</description>
  <content>&lt;p&gt;This is Pagename testing 1 2 3&lt;/p&gt;</content>
  <keywords />
  <slug>Testing-Page-Name-This-is-Title</slug>
  <parent>00000000-0000-0000-0000-000000000000</parent>
  <isfrontpage>False</isfrontpage>
  <showinlist>True</showinlist>
  <ispublished>True</ispublished>
  <datecreated>2010-10-30 04:19:36</datecreated>
  <datemodified>2010-10-30 04:20:40</datemodified>
</page>

 

I want to add two childs to it.

 

<PageName> and <Menu>

 

To each new page that I make.

 

I have the fields made on the Pages.aspx Admin page it seems to work ok but,

it does not save to the xml file. 

 

When I run it I do not get any errors.  Seems to save the page as usual just did not add my new elements.

 

After I press save and look at the xml file its only this:

 

<page>
  <title>Testing Page Name This is Title</title>
  <description>Main</description>
  <content>&lt;p&gt;This is Pagename testing 1 2 3&lt;/p&gt;</content>
  <keywords />
  <slug>Testing-Page-Name-This-is-Title</slug>
  <parent>00000000-0000-0000-0000-000000000000</parent>
  <isfrontpage>False</isfrontpage>
  <showinlist>True</showinlist>
  <ispublished>True</ispublished>
  <datecreated>2010-10-30 04:19:36</datecreated>
  <datemodified>2010-10-30 04:20:40</datemodified>
</page>

 

New info updated but no <PageName> or <Menu> elements with data.

 

So I need to know how to make a new element then save it. 

I updated the Pages.aspx,Pages.cs and the labels.resx file.

 

Is there something else I need to update?

Thanks,

 

Brian Davis

Java Blog

Oct 31, 2010 at 1:15 AM

Also tried to add a reference to it in the blogengine.core   but have not figure out how to update it.

Coordinator
Oct 31, 2010 at 2:01 AM

The XML for pages is output and input within the BE core.  This is a separate project that gets compiled (into BlogEngine.Core.dll).

Not sure which version of BE you are using, but you can download the Source version of it, and modify the file.  The file to modify within the BE core is Pages.cs in the Providers\XmlProvider provider.  Here is what the file looks like in the latest developer build of BE.

You would need to download the Source version, which includes the BE core project.  Make your changes, and then recompile the core.

Oct 31, 2010 at 2:44 AM
Edited Oct 24, 2011 at 6:01 PM

Thanks this makes lots of sense for me now I understand.

 

Is there a way to do this with the BE Core with only the Visual Web Developer 2010 Express Edition? OR use 2010 Express Edition for C# ?

Or is there another way to do this with free software?

 

I have downloaded 2010 Pro Visual Studio but only have 60 days to use it.  Want to know after the 60 days what are the free alternatives to the Pro Edition?

 

public override void InsertPage(Page page)
        {
            if (!Directory.Exists(string.Format("{0}pages", this.Folder)))
            {
                Directory.CreateDirectory(string.Format("{0}pages", this.Folder));
            }

            var fileName = string.Format("{0}pages{1}{2}.xml", this.Folder, Path.DirectorySeparatorChar, page.Id);
            var settings = new XmlWriterSettings { Indent = true };

            using (var writer = XmlWriter.Create(fileName, settings))
            {
                writer.WriteStartDocument(true);
                writer.WriteStartElement("page");

                 writer.WriteElementString("pagename", page.PageName);
  
                writer.WriteElementString("title", page.Title);
                writer.WriteElementString("description", page.Description);
                writer.WriteElementString("content", page.Content);
                writer.WriteElementString("keywords", page.Keywords);
                writer.WriteElementString("slug", page.Slug);
                writer.WriteElementString("parent", page.Parent.ToString());
                writer.WriteElementString("isfrontpage", page.IsFrontPage.ToString());
                writer.WriteElementString("showinlist", page.ShowInList.ToString());
                writer.WriteElementString("ispublished", page.IsPublished.ToString());
                writer.WriteElementString(
                    "datecreated", 
                    page.DateCreated.AddHours(-BlogSettings.Instance.Timezone).ToString(
                        "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
                writer.WriteElementString(
                    "datemodified", 
                    page.DateModified.AddHours(-BlogSettings.Instance.Timezone).ToString(
                        "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));

                writer.WriteEndElement();
            }
        }

 

 

 

Thanks,

 

Brian Davis

Coordinator
Oct 31, 2010 at 2:51 AM

One or both of the Express editions will work.  The C# Express Edition can definitely compile the BE core.  Visual Web Developer Express Edition *probably* can compile it -- not 100% sure.  But you can definitely get by with the free Express editions.