有没有办法查询XML文档以使用Xpath 1.0返回给定属性的最大值?
例如,有没有办法获得最大ID?
<?xml version="1.0" encoding="utf-8"?>
<library>
<book id="2" name="Dragon Tatoo"/>
<book id="7" name="Ender's Game"/>
<book id="3" name="Catch 22"/>
<book id="1" name="Lord of the rings"/>
</library>
Run Code Online (Sandbox Code Playgroud) 我在PowerShell脚本中遇到问题:
当我想将Hashtable传递给函数时,此哈希表不会被识别为哈希表.
function getLength(){
param(
[hashtable]$input
)
$input.Length | Write-Output
}
$table = @{};
$obj = New-Object PSObject;$obj | Add-Member NoteProperty Size 2895 | Add-Member NoteProperty Count 5124587
$table["Test"] = $obj
$table.GetType() | Write-Output ` Hashtable
$tx_table = getLength $table `Unable to convert System.Collections.ArrayList+ArrayListEnumeratorSimple in System.Collections.Hashtable
Run Code Online (Sandbox Code Playgroud)
为什么?
我尝试在php脚本中使用curl访问web:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.fr");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
Run Code Online (Sandbox Code Playgroud)
它返回:
无法连接到www.google.fr端口443:连接被拒绝
这是正常的,我是一个代理,它需要我的Windows凭据(NTLM)允许互联网流量.
在MS Powershell中,这有效:
$request = New-Object System.Net.WebCLient
$request.UseDefaultCredentials = $true
$request.Proxy.Credentials = $request.Credentials
$request.DownloadFile($url, $path)
Run Code Online (Sandbox Code Playgroud)
使用"DefaultCredentials"(= Windows Credentials)并将它们发送到代理允许我访问Web.但我现在不知道它是如何工作的.
如果我使用Firefox导航,Firefox总是会添加一个Proxy-Authorization标头,其值为:Negociate blablablablababalazdlad ...
我想将.NET useDefaultCredentials解决方案转换为cURL,我试过:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.fr");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM );
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM );
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close …Run Code Online (Sandbox Code Playgroud) 我尝试创建一个扩展核心" 实体 "类型的Symfony Custom 类型.
但是我想在Select2版本4.0.0中使用它(ajax现在可以使用"select"html元素,而不是像以前一样使用隐藏的"输入").
这通过设置选项(请参阅configureOption)来工作:
'choices'=>array()
Run Code Online (Sandbox Code Playgroud)
Select2识别html"select"的内容,并使用ajax工作.但是当表单被回发时,Symfony无法识别所选择的选项,(因为不允许这样做?)
Symfony\Component\Form\Exception\TransformationFailedException
Unable to reverse value for property path "user": The choice "28" does not exist or is not unique
Run Code Online (Sandbox Code Playgroud)
我尝试了几种使用EventListeners或Subscribers的方法,但我找不到工作配置.
使用Select2 3.5.*我解决了表单事件的问题并覆盖了隐藏的formtype,但是这里扩展实体类型要困难得多.
如何构建我的类型以让它管理我的entites的逆向转换?
自定义类型:
<?php
namespace AppBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
class AjaxEntityType extends AbstractType
{
protected $router;
public function __construct($router)
{
$this->router = $router;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{ …Run Code Online (Sandbox Code Playgroud) 尝试使用 Postgres 执行与此处相同的操作:
http://codeutopia.net/blog/2011/02/19/using-spatial-data-in-doctrine-2/
我对“convertToDatabaseValue”函数有问题(请参阅此处:http : //doctrine-dbal.readthedocs.org/en/latest/reference/types.html#custom-mapping-types)
我的自定义类型:
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class PointType extends Type
{
const POINT = 'point';
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return 'POINT';
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return new Point($value[0],$value[1]);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return "'".$value->getLongitude().','.$value->getLatitude()."'";
}
public function getName()
{
return self::POINT;
}
}
Run Code Online (Sandbox Code Playgroud)
手动,我可以使用以下 SQL 插入此点:
INSERT INTO points (pointtype,name,score) VALUES ('2.43145,42.84214',"My Place",3241)
Run Code Online (Sandbox Code Playgroud)
但学说 DBAL,创建以下代码:
'INSERT INTO points (pointtype,name,score) VALUES (?,?,?)' with params …Run Code Online (Sandbox Code Playgroud) symfony ×2
curl ×1
doctrine ×1
doctrine-orm ×1
php-curl ×1
postgresql ×1
powershell ×1
webclient ×1
xml ×1
xpath ×1
xpath-1.0 ×1