在 NetBeans 中混合 PHP 和 XML 语法 (7.0.1)
我正在使用 NetBeans IDE 7.0.1 处理 XML 中的 PHP;问题是我无法让 NetBeans 理解我正在使用的语言(s)(同时)。
例如,当由 标签正确分隔时,HTML 标记和内联 PHP 会突出显示并自动完成,但是仅对于
是这样。 php
扩展名。
如果我尝试使用 XML,它根本不会将 PHP 代码视为 PHP(或除我假设的文本节点之外的任何内容)。当给定文件具有 . xml
扩展名。
如果我将扩展名更改为 .php
,就像 HTML 的情况一样,我的内联 PHP 会被识别,但我的 XML 开始表现奇怪(无法识别匹配的节点标记;声明无法识别,但这是预期的等等。
)
是否有任何方法可以让 NetBeans 根据标记分隔清晰地解释 PHP 和 XML 的混合文件?
我尝试使用 ASP 样式标记 <%
,但是当文件为 .php
时,这些标记对 XML 识别没有任何帮助;当我将其切换为 .xml
时,使用什么 PHP 分隔符并不重要,它只是无法识别任何 PHP。
换句话说,如果 NetBeans 不可避免地会失败,人们会建议使用哪种 IDE?
I'm dealing with PHP in XML, using NetBeans IDE 7.0.1; the problem is I'm having trouble getting NetBeans to understand what language(s) I'm working with (simultaneously).
For instance, HTML markup and inline PHP is highlighted and auto-completed appropriately when properly delimited by <?php
tags, this however is only true with the .php
extension.
If I try to use XML, it simply doesn't observe the PHP code as PHP (or anything besides a text node I'm assuming) This is true when a given file has the .xml
extension.
If I change the extension to .php
, as in the case of HTML, my inline PHP becomes recognized, but my XML starts behaving strangely (no recognition of matching node tags; the <?xml
declaration isn't recognized, but that's expected; etc.)
Is there any way to get NetBeans to cleanly interpret a mixed file of PHP and XML based on tag delimitation?
I tried using ASP style tags <%
, but those don't help the XML recognition when the file is .php
anyways; when I switch it out to .xml
, it doesn't matter what PHP delimiters I use, it just doesn't recognize any PHP.
To phrase my question differently, if NetBeans will inevitably fail, what IDE would one suggest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Netbeans 中,您可以指定与文件关联的 mime 类型:
工具>选项>杂项>文件
但是,您无法更改
.xml
文件的 MIME 类型。将.php
扩展名更改为 mimetext/xml
使 PHP 文件仅使用 XML 格式。那里没有帮助。但是,我要做的是将
xhtml
扩展指定为text/x-php5
类型。另外,我必须禁用该项目的短标签(文件 > 项目属性 > 源 > 允许短标签)。乍一看似乎有效。如果您给我一个 XML 示例文件,我也许能够得到一个完整的工作解决方案。另外,如果您创建一个新的扩展类型并将其关联为
text/x-php5
,它可能会起作用。 dxml(动态XML?)pxml(PhpXML?)等编辑:在使其工作的过程中,我忽略了简单地禁用短标签。在具有 XML 声明的 PHP 文件中,您可以使用 XHTML。
另外,我不确定您是否可以使所有模式验证内容正常工作。但我确实知道语法突出显示是很好的选择。
In Netbeans, you can specify what mime type is associated with the file:
Tools > Options > Miscellaneous > Files
However, you cannot change the mime type for
.xml
files. Changing the.php
extension to be mimetext/xml
makes PHP files to simply use the XML formatting. No help there.However, what I have gotten to work is specifying
xhtml
extensions to be typetext/x-php5
. Also, I had to disable shorttags for the project (File > Project Properties > Sources > Allow short tags). At a glance it seems to be working. If you gave me an example file of XML, I may be able to get a complete working solution.Also, if you create a new extension type and associate it as
text/x-php5
, it may work. dxml (Dynamic XML?) pxml (PhpXML?) etc.Edit: In the process of getting this to work, I overlooked simply disabling shorttags. In PHP files that have an XML declaration, you can get XHTML to work.
Also, I'm not sure that you can get all the schema validation stuff to work. But I do know syntax highlighting is good to go.
我不能肯定地说太多关于 NetBeans 的事情,因为除了 Java 桌面应用程序之外,我从未将它用于任何其他应用程序,但是基于 Eclipse 的 Aptana 是我用于 Web 开发的首选 IDE。它开箱即用地支持多种语言(甚至框架)。不过,语法突出显示有点粗略,因为它使用类似于 TextMate 的引擎,但在多语言文件上不会出现严重错误。
I can't say much about NetBeans for sure as I've never used it for anything but Java desktop apps, but the Eclipse-based Aptana is my go-to IDE for web development. It supports plenty of languages (and even frameworks) out of the box. Syntax highlighting is a little sketchy, though, in that it uses an engine similar to TextMate, but it shouldn't bug out horribly on multilingual files.