简体   繁体   English

umbraco获取内容部分为xml

[英]umbraco get content part as xml

I'm trying to get part of umbraco node content as xml doc. 我正在尝试将umbraco节点内容的一部分作为xml文档。 I need to update this part of code from the code behind. 我需要从后面的代码中更新这部分代码。 I use the code like this: 我使用这样的代码:

    Document doc = new Document(1214);
    XmlDocument xmlDoc = new XmlDocument();
    umbraco.cms.businesslogic.property.Property items = doc.getProperty("fundItems");
    XmlNode fundsNode = items.ToXml(xmlDoc);

The problem is that I get an error: Data at the root level is invalid. 问题是我得到一个错误: 根级别的数据无效。 Line 1, position 1. 第1行,位置1。

Not sure if I use ToXml method properly? 不确定我是否正确使用ToXml方法? There seems not to be other solution but I can't find any proper documentation for this method or solutions in the internet. 似乎没有其他解决方案,但我在互联网上找不到任何有关此方法或解决方案的适当文档。

Thanks 谢谢

Without seeing the XML it's difficult to say what the problem is, but that sounds like it may not be a valid XML document. 如果没有看到XML,就很难说出问题所在,但这听起来可能不是有效的XML文档。 If it's like many properties I've run across before, it's not stored as a valid XML document (complete with header), but simply the XML data, and thus trying to make a document from it might not work. 如果就像我之前遇到的许多属性一样,它不会存储为有效的XML文档(带有标头),而只是存储为XML数据,因此尝试从中创建文档可能无法正常工作。

I had some trouble trying to access an XML page property. 我在尝试访问XML页面属性时遇到了一些麻烦。 I tried parsing it into a doc like you did and didn't get it right immediately, so I tried something else. 我尝试像您一样将其解析为文档,但没有立即正确处理,因此我尝试了其他方法。 What worked for me was to enumerate through the items, as Umbraco recognized them as a collection. 对我而言,最有效的方法是对这些物品进行枚举,因为Umbraco认为它们是一个收藏品。 It looked something like this: 它看起来像这样:

Node node = new Node(1214);
var items = node.GetProperty("fundItems");

foreach (var item in items)
{
    foreach (XElement data in item.BaseElement.Elements("data"))
    {
        if (data.Attribute("alias").Value == "alias1")
        {
            // action for each item
        }
    }
}

The XML was formatted like that shown on this Umbraco project page . XML的格式类似于该Umbraco项目页面上显示的格式。 I realize your XML and situation may not be analogous to mine, but I hope this helps. 我知道您的XML和情况可能与我的不相似,但我希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM