用于格式化PHP代码的Unix或VIM命令(Unix or VIM command to format PHP code)
我知道你可以使用
indent
命令来美化c
代码。 我想用php做同样的事情,但命令是给出错误(它只用于c我认为)是否有一种标准方法用命令格式化PHP代码? 我会接受OS X附带的unix命令或VIM命令。I know that you can use the
indent
command to beautifyc
code. I want to do the same thing with php but the command is giving errors (it is intended for c only I believe) is there a standard way to formatt php code with a command? I would be open to either a unix command that comes with OS X or a VIM command.
原文:https://stackoverflow.com/questions/4233960
最满意答案
文本值由XLinq解释为XText。 因此您可以轻松检查节点是否为XText类型,或者通过检查NodeType来查看:
// get all text nodes var textNodes = document.DescendantNodes() .Where(x => x.NodeType == XmlNodeType.Text);
然而,这让我觉得你只想找到那些看起来有点孤独的文本命名为textvalue。 没有真正的方法来认识这种有效但不寻常的事情。 您可以检查父项是否被命名为“名称”,或者文本节点本身是单独还是不可见:
// get 'lost' textnodes var lastTextNodes = document.DescendantNodes() .Where(x => x.NodeType == XmlNodeType.Text) .Where(x => x.Parent.Nodes().Count() > 1);
编辑一个额外的评论,我看到很多人声称这个XML是无效的。 我不同意这一点。 尽管它并不漂亮,但根据我的知识(和验证者)
Text values are interpreted by XLinq as XText. therefore you can easily check if a node is of type XText or by checking the NodeType see:
// get all text nodes var textNodes = document.DescendantNodes() .Where(x => x.NodeType == XmlNodeType.Text);
However, it strikes me that you only want to find that piece of text that seems a bit lonely named textvalue. There is no real way to recognize this valid but unusual thing. You can either check if the parent is named 'name' or if the textNode itself is alone or not see:
// get 'lost' textnodes var lastTextNodes = document.DescendantNodes() .Where(x => x.NodeType == XmlNodeType.Text) .Where(x => x.Parent.Nodes().Count() > 1);
edit just one extra comment, i see that many people claim that this XML is invalid. I have to disagree with that. Although its not pretty, it's still valid according to my knowledge (and validators)
相关问答
更多-
你可以尝试: var result = ( from entry in loaded.Descendants("entry") where entry.Descendants("SortOrder").Count() > 0 select new CcList { LinkHref = entry.Element("link").Attribute("href").Value, Id = entry.Element("id").Value, ...
-
使用XPath :(没有完成错误检查) XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable()); nsm.AddNamespace("def", "http://www.fake.org/namespace/"); XDocument doc = XDocument.Parse(xml); string code = doc .XPathSelectElement(@"/def:IDMResponse/def:A ...
-
文本值由XLinq解释为XText。 因此您可以轻松检查节点是否为XText类型,或者通过检查NodeType来查看: // get all text nodes var textNodes = document.DescendantNodes() .Where(x => x.NodeType == XmlNodeType.Text); 然而,这让我觉得你只想找到那些看起来有点孤独的文本命名为textvalue。 没有真正的方法来认识这种有效但不寻常的事情。 ...
-
创建匿名(或引入自己的类)实例并在foreach循环中使用它 var tests = xInformations.Descendants("test") .Select(x => { new { Id = x.Attribut ...
-
当你要查找的元素不是当前元素的直接子元素(或XDocument根)时,你必须使用Descendants 。 string info = doc.Descendants(tag).First().Attribute(attribute).Value; You have to use Descendants when element you're looking for is not direct child of current element (or root for XDocument). string ...
-
你有没有尝试过: string text = doc.Root.Value; ? Have you tried: string text = doc.Root.Value; ?
-
由于您已定义了命名空间,请尝试以下代码: XDocument xmlResponse = XDocument.Load("yourfile.xml"); //Or you can use XDocument xmlResponse = XDocument.Parse(response) XNamespace ns= "http://platform.intuit.com/api/v1"; var test = xmlResponse.Descendants(ns+ "Erro ...
-
正如ZevSpitz已经提到的,您的XML无效。 我修改了一下以便能够测试我的代码:
title gfgdgdggd -
为XDocument指定默认名称空间会给出空值(Specifiying a default namespace for XDocument gives empty value)[2022-06-05]
我想我明白为什么我没有得到默认的命名空间。 根据MSDN : 使用C#创建XML树时,即使XML树将使用默认命名空间进行序列化,但如果命名空间没有作为属性持久保存在XML树中,该方法将不会将该命名空间报告为默认命名空间。 所以我可能需要显式设置xmlns属性: class Program { static void Main(string[] args) { var xmlRoot = new XElement(XName.Get("root", "http://somena ... -
从XDocument获取数据(Get data from XDocument)[2023-08-22]
PubDate = DateTime.ParseExact(xml.Root.Elements("pubDates") .Elements("date") .Where(n => n.Attribute("format").Value == "standard") .FirstOrDefault() .Value , "yyyy-mm-dd", CultureInfo.InvariantCulture); PubDate = DateTime.ParseExact(xml.Root.Elements("p ...