首页 \ 问答 \ MarkLogic 8服务器端javascript:将现有的xml转换为json(MarkLogic 8 server-side javascript: convert existing xml to json)

MarkLogic 8服务器端javascript:将现有的xml转换为json(MarkLogic 8 server-side javascript: convert existing xml to json)

我在MarkLogic 8中尝试新的服务器端JavaScript API。我主要对搜索感兴趣。 我看到的示例首先将JSON保存到数据库中,然后搜索本机JSON。 这不是我的用例,因为我的公司已经有大量的原生XML存储在数据库中。 我想使用javascript搜索文档,我希望搜索结果为JSON。

这甚至可以从JavaScript? 当我运行下面的代码(从其中一个示例中修改)时,结果是一个字符串数组,其中每个字符串都是一个完整的XML文档。 不是我想要的。 是否有API调用将每个结果转换为JSON?

var count = 0;
var results = [];
for (var result of cts.search(cts.wordQuery("value1"))) {
    count++;
    results.push(result); 
};
results.push(fn.concat("Count = ", count));
results;

I'm trying out the new server-side javascript API in MarkLogic 8. I'm mainly interested in search. The examples I've seen start by saving JSON into the database and then search the native JSON. That is not my use case because my company has tons of native XML already stored in the database. I want to use javascript to search for documents and I want the search results in JSON.

Is that even possible from javascript? When I run the code below, (modified from one of the examples) the result is an array of string, where each string is a complete XML document. Not what I want. Is there an API call to convert each result to JSON?

var count = 0;
var results = [];
for (var result of cts.search(cts.wordQuery("value1"))) {
    count++;
    results.push(result); 
};
results.push(fn.concat("Count = ", count));
results;

原文:https://stackoverflow.com/questions/30598500
更新时间:2022-01-12 13:01

最满意答案

如您所知,JPG压缩通过更改图像以产生较小的文件大小来工作。 您没有看到质量逐渐恶化的原因是因为您每次都使用相同的压缩设置。

该算法改变源图像刚好足以适应压缩轮廓 - 换句话说,再次以50%压缩50%JPG的结果将产生相同的图像,因为图像不再需要改变。

您可以在Photoshop中测试 - 以30%质量的JPG保存照片。 重新打开刚刚保存的文件,然后转到Save for Web - 在PNG(未压缩/原始)和JPG 30%之间切换 - 没有区别。

希望这可以帮助。


As you know, JPG compression works by altering the image to produce smaller file size. The reason why you don't see progressively worse quality is because you're using the same compression setting each time.

The algorithm alters the source image just enough to fit into the compression profile - in other words, compressing the result of 50% JPG again at 50% will produce the same image, because the image doesn't need to be altered any more.

You can test this in Photoshop - save a photo out at say 30% quality JPG. Reopen the file you just saved, and go to Save for Web - flip between PNG (uncompressed/original) and JPG 30% - there will be no difference.

Hope this helps.

相关问答

更多
  • 输出像素值最多基于2x2输入邻域。 这自动意味着比例因子限制为1/2。 大于1的比例因子需要插值,此代码不执行此操作。 这种类型的错误处理和清理非常脆弱。 只需使用RAII。 缩放0.23需要每个输出像素5x5输入像素,这是代码无法做到的。 库请求在SO上是偏离主题的,只需使用搜索引擎。 Output pixel values are based on at most a 2x2 input neighborhood. This automatically means scale factors are l ...
  • UIImage提供图像的位图(未压缩)版本,可用于将图像渲染到屏幕。 可以通过降低图像的质量(有效的颜色方差)来压缩图像的JPEG数据,但这仅在JPEG数据中。 将压缩的JPEG解压缩到UIImage它再次需要完整的位图大小(基于颜色格式和图像尺寸)。 基本上,保持最佳质量的图像,您可以在上传之前进行显示和压缩。 A UIImage provides a bitmap (uncompressed) version of the image which can be used for rendering th ...
  • imageFromSampleBuffer方法imageFromSampleBuffer可以工作,但实际上我正在使用它的更改版本,但如果我没有记错,则需要将outputSettings设置为正确。 我认为您需要将密钥设置为kCVPixelBufferPixelFormatTypeKey ,将值设置为kCVPixelFormatType_32BGRA 。 例如: NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; ...
  • hi you can check this code hop it will help you... case NSStreamEventHasBytesAvailable: { uint32_t max_size = 1000000; // Max size of the received imaged you can modify it as your reqirement. NSMutableData* buffer = [[NSMutableData alloc] initWi ...
  • 你显然不想关闭流,因为这会破坏性能。 由于您控制客户端服务器连接,因此在发送图像数据之前,请向下发送图像中的字节数。 更好的是,发送图像中的字节数,图像数据和最后一个容易识别的序列号,这样您就可以快速验证数据是否已实际到达。 比实际检查文件结束标记更容易,更有效。 当然,您也可以在收到字节数后检查它。 很容易。 当然,除了不寻常的情况之外,所有这些对于屏幕共享风格目的来说都是非常低效的。 在大多数情况下,只有一小部分要镜像的屏幕实际上随每帧而变化。 如果你试图用每一帧发送整个屏幕,你很快就会使你的连接饱和, ...
  • 我相信原因是UIImage imageNamed会导致数据被解压缩并存储在它的缓存中,而UIImage imageWithContentsOfFile会加载压缩数据,但在您需要显示它之前不会对其进行解压缩。 I believe the reason is that UIImage imageNamed causes the data to be decompressed and stored in it's cache, whereas UIImage imageWithContentsOfFile loa ...
  • 你可以使用这个,两个占位符图像交替显示在所有单元格中。 如果将更多占位符图像添加到数组中,则会自动考虑项目数量。 func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let event = posts[indexPath.row] let cell = eventsCollectionView.de ...
  • 如您所知,JPG压缩通过更改图像以产生较小的文件大小来工作。 您没有看到质量逐渐恶化的原因是因为您每次都使用相同的压缩设置。 该算法改变源图像刚好足以适应压缩轮廓 - 换句话说,再次以50%压缩50%JPG的结果将产生相同的图像,因为图像不再需要改变。 您可以在Photoshop中测试 - 以30%质量的JPG保存照片。 重新打开刚刚保存的文件,然后转到Save for Web - 在PNG(未压缩/原始)和JPG 30%之间切换 - 没有区别。 希望这可以帮助。 As you know, JPG comp ...
  • 原来转移编码是个问题。 Turns out the Transfer-Encoding was the issue.
  • 这段代码用于处理图像元数据 - 如果存在 - 您可以使用它来更改图像元数据中的任何值。 请注意,更改元数据中的DPI值实际上不会处理图像并更改DPI。 #import -(NSData *)changeMetaDataInImage { NSData *sourceImageData = [[NSData alloc] initWithContentsOfFile:@"~/Desktop/1.jpg"]; if (sourceImageData ! ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。