我有一个返回XElement
's 的API,我希望这些文件背后的文档XElement
是不可变的(只读).我需要它:
XDocument
在某些情况下,创建一个可能是性能"繁重"操作的副本.似乎无法继承和覆盖XDocument
/ XElement
/中的必要行为 XContainer
,因为所有虚拟方法都标记为internal
:
internal virtual void XContainer.AddAttribute(XAttribute a)
{
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是 - 有没有办法让它发生,或者最好有一个不同的API,它会返回类似的东西XPathNavigator
,或者最好有自己的类IReadOnlyXElement
,等等?
如果我没弄错的话,我记得异步I/O(Node.js,Nginx)的"事件循环"模型不适合提供大型文件.
是这种情况,如果是这样,周围有方法吗?我正在考虑在Node中编写一个实时文件浏览器/文件服务器,但文件可能在100MB到3GB之间.我会假设事件循环将阻塞,直到文件完全服务?
我有以下XML文档:
<text xmlns:its="http://www.w3.org/2005/11/its" >
<its:rules version="2.0">
<its:termRule selector="//term" term="yes" termInfoPointer="id(@def)"/>
</its:rules>
<p>We may define <term def="TDPV">discoursal point of view</term>
as <gloss xml:id="TDPV">the relationship, expressed through discourse
structure, between the implied author or some other addresser,
and the fiction.</gloss>
</p>
</text>
Run Code Online (Sandbox Code Playgroud)
termInfoPointer
是一个指向<gloss xml:id="TDPV">
元素的XPath表达式.
我使用LINQ-to-XML来选择它.
XElement term = ...;
object value = term.XPathEvaluate("id(@def)");
Run Code Online (Sandbox Code Playgroud)
我得到以下异常: System.NotSupportedException: This XPathNavigator does not support IDs.
我找不到解决这个问题的方法,所以我尝试id()
用其他表达式替换:
//*[@xml:id='TDPV'] // works, but I need to use @def
//*[@xml:id=@def]
//*[@xml:id=@def/text()]
//*[@xml:id=self::node()/@def/text()]
Run Code Online (Sandbox Code Playgroud)
但这些都不起作用.
有没有办法id() …
我试图将我的chrome浏览器连接到NodeJs Server.所有代码在其他机器上运行良好.但是当我在我的机器上运行时,它既没有出错也没有成功.这是代码
服务器代码:
var server = http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
var io = require('socket.io').listen(server);
io.sockets.on('message', function (socket) {
socket.emit('news', { hello: 'world' });
});
Run Code Online (Sandbox Code Playgroud)
这是客户代码.
<script>
var socket = io.connect('http://localhost:3000/');
//console.log(socket);
socket.on("message",function(data){
console.log(data);
})
</script>
Run Code Online (Sandbox Code Playgroud)
请纠正我在哪里做错了.客户端中的console.log()不起作用.我尝试使用断点在chrome调试器中检查它,但它永远不会到那一点.
我正在玩HttpListener和Async CTP
class HttpServer : IDisposable
{
HttpListener listener;
CancellationTokenSource cts;
public void Start()
{
listener = new HttpListener();
listener.Prefixes.Add("http://+:1288/test/");
listener.Start();
cts = new CancellationTokenSource();
Listen();
}
public void Stop()
{
cts.Cancel();
}
int counter = 0;
private async void Listen()
{
while (!cts.IsCancellationRequested)
{
HttpListenerContext context = await listener.GetContextAsyncTask(); // my extension method with TaskCompletionSource and BeginGetContext
Console.WriteLine("Client connected " + ++counter);
// simulate long network i/o
await TaskEx.Delay(5000, cts.Token);
Console.WriteLine("Response " + counter);
// send response
}
listener.Close(); …
Run Code Online (Sandbox Code Playgroud) 有没有办法可以从我的visual studio卸载TypeScript 0.9并返回到0.8.3?我通过升级犯了一个巨大的错误.它基本上杀死了我的所有代码.
.net ×2
linq-to-xml ×2
node.js ×2
api ×1
asynchronous ×1
c# ×1
socket.io ×1
typescript ×1
webserver ×1
xelement ×1
xpath ×1