Tag: xml

用xml2jsparsing

我是node.js新手,需要parsingXML 。 在JS中,我只是使用DOMParser并使用getElementsByTagName来获取我想要的值。 我刚刚切换到节点,并正在使用xml2js (愿意考虑替代品)。 我一直无法弄清楚如何parsing通过响应得到我所期待的。 代码如下: function parseBody(body){ var parseString = require('xml2js').parseString; var xml = body parseString(xml, function (err, result) { console.dir(result); }); 这里是传递给函数的XML: <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:int=\"realURLHere"> <soapenv:Header/> <soapenv:Body> <int:readResponse> <response> <request>?</request> <cust> <fName>?</fName> </cust> </response> </int:readResponse> </soapenv:Body> </soapenv:Envelope> 这是我的function的输出: { 'soapenv:Envelope': { '$': { 'xmlns:soapenv': 'http://schemas.xmlsoap.org/soap/envelope/', 'xmlns:int': 'realURLHere' }, 'soapenv:Body': [ [Object] ] […]

Node.js xml2jsparsing器未定义

所有, 我想通过xml2jsparsing一个HTTP响应XML,并运行到一个错误。 我试图按照这些说明: https : //programmerblog.net/parse-xml-using-nodejs/ 我已经安装了模块,似乎正常运行。 我得到的错误。 parser.parseString(soapreplyx, function (err, result) { ^ ReferenceError: parser is not defined 我的应用程序代码如下所示。 // APP – INCLUDE const express = require('express') const path = require("path") const bodyParser = require("body-parser") const hbs = require('hbs') var xml2js = require('xml2js'); var parser = new xml2js.Parser(); // APP – DEFINITION const app […]

使用XSL计算XML URL中的数据元素并在html中打印

我有一个XML URL 1 。 我的输出需要是类似的东西 2009-12-01:2 2009-12-02:2 我试图用XSL实现这个(这是我第一次使用它,所以我的代码可能看起来很愚蠢)。 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <xsl:copy-of select="document('http://vhost11.lnu.se:20090/final/getFilterData.php?parameter=User_IDpatient&value=3')/EData/test_sessionID"/> 2009-12-01 : <xsl:value-of select="count(EData/test_sessionID[test_datetime=2009-12-01 18:00:00])" /> 2009-12-02 : <xsl:value-of select="count(EData/test_sessionID[test_datetime=2009-12-02 18:00:00])" /> </body> </html> </xsl:template> </xsl:stylesheet> 即使这个代码有效,也会有一些问题,例如date和时间戳被合并。 理想情况下,计数只能在test_datetime元素的date部分完成。 另一个是如何自动取得date,而不是手动写入。 我使用node.js作为我的服务器。 在控制台或Chrome的开发人员工具中,我不会收到任何错误。 所以,在如何进行中有点失落。

XPath如何处理XML名称空间?

XPath如何处理XML名称空间? 如果我使用 /IntuitResponse/QueryResponse/Bill/Id parsing下面的XML文档,我得到0个节点。 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2016-10-14T10:48:39.109-07:00"> <QueryResponse startPosition="1" maxResults="79" totalCount="79"> <Bill domain="QBO" sparse="false"> <Id>=1</Id> </Bill> </QueryResponse> </IntuitResponse> 但是,我没有在XPath中指定名称空间(即http://schema.intuit.com/finance/v3不是path中每个标记的前缀)。 如果我没有明确地告诉XPath XPath如何知道我想要的Id ? 我想在这种情况下(因为只有一个名称空间),XPath可以完全忽略xmlns 。 但是,如果有多个命名空间,事情可能会变得丑陋。

如何在MongoDB中存储XML格式的数据?

我有几个XML格式的文件。 每个文件包含XML头和约15-20项。 我想将这些文件存储在MongoDB中,我认为这些文件以JSON格式存储数据。 这里是我想要存储在MongoDB中的数据样本。 <?xml version="1.0" encoding="utf-8"?> <rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0"> <channel> <title>Channel Title</title> <link>Channel link</link> <description>Channel desc</description> <!– Item 1 –> <item> <title>Your Title</title> <link>Your link</link> <pubDate>Published date</pubDate> <description>Your description</description> </item> <!– Item 2 –> <item> <title>Your Title</title> <link>Your link</link> <pubDate>Published date</pubDate> <description>Your description</description> </item> </channel> </rss> 如何进行? 任何人都可以帮助使用一些例子和示例代码如何将这些数据存储在MongoDB中? 注意:我将使用Node […]

在下载XML Feed时处理多种编码scheme

我正尝试通过以下url阅读Feed: http://www.chinanews.com/rss/scroll-news.xml 使用请求模块 。 但我得到的东西有 ʷ ) ( й ) ޹ 。 在回顾XML我发现编码被设置为<?xml version="1.0" encoding="gb2312"?> 但试图设置编码为gb2312 ,我得到未知的编码错误。 request({ url: "http://www.chinanews.com/rss/scroll-news.xml", method: "GET", headers: { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Host": "www.chinanews.com", "Accept-Language": "en-GB,en-US;q=0.8,en;q=0.6" }, "gzip": true, "encoding": "utf8" }, (err, resp, data) => { console.log(data); }); 有没有一种方法,我可以得到的数据不考虑它的编码? 我应该如何处理这个?

将XMLstring编码为EXI并通过websocket发送

首先,我使用的是客户端 – 服务器体系结构,android为客户端,node.js为服务器,它们通过Socket.io库连接,因此它们使用的是websocket。 我怀疑的是,我正在用Java的XMLSerializer生成XMLstring,我想将它编码为EXI并将其发送到服务器,因此,是否可以在不使用文件的情况下编码XML-EXI? 直接从string到string? 因为我看到的所有例子都假设我的XML是在一个文件中,而我想把输出转换成另一个文件。 另一个疑问是,我可以把EXI作为string吗? 因为我已经build立了客户端和服务器之间的通信,但是他们只是发送string,我不知道如果我能发送整个文件,在这种情况下,会有任何不同的数据发送量?

WCF在node.js中的Web服务

任何人都可以帮我说下面的代码有什么问题 var BasicHttpBinding = require('wcf.js').BasicHttpBinding , Proxy = require('wcf.js').Proxy , binding = new BasicHttpBinding() , proxy = new Proxy(binding,"http://www.restfulwebservices.net/wcf/WeatherForecastService.svc") , message = '<Envelope xmlns=' + '"http://schemas.xmlsoap.org/soap/envelope/">' + '<Header />' + '<Body>' + '<GetCitiesByCountry xmlns="http://www.restfulwebservices.net/ServiceContracts/2008/01">' + '<Country>korea</Country>' + '</GetCitiesByCountry>' + '</Body>' + '</Envelope>' proxy.send(message, "http://www.restfulwebservices.net/ServiceContracts/2008/01/IWeatherForecastService/GetCitiesByCountry", function(response, ctx) { console.log(response) }); 我得到下面的错误 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault> <faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode><faultstring xml:lang="en-US">The […]

在nodejs中最好的xmlvalidation器

您好我正在检查xml数据是否是一个有效的或不在nodejs.I使用xmldoc模块,但似乎没有引发任何错误时,我传递了一个错误的XML数据。 我也尝试下面的xmltojsonparsing器是我的代码 var xml2js = require('xml2js') var parser = new xml2js.Parser(); parser.on('end', function(POST_VALUE) { console.log(POST_VALUE) }); parser.parseString(POST_VALUE); 在POST_VALUE我传递了一个无效的XML仍然没有抛出我的任何错误,但没有返回任何JSON数据我进一步分析,有一个选项叫validator.But它表示为一个callable.And我不知道如何使用它。 我卡在这里任何帮助将是非常有益的。

使用Node.js遍历XML文档最快捷的方法?

从类似的问题,我发现了XPath ,它看起来非常快,但我不能用Node.js: > var xp = new XPathEvaluator(); ReferenceError: XPathEvaluator is not defined at repl:1:14 at REPLServer.self.eval (repl.js:110:21) at repl.js:249:20 at REPLServer.self.eval (repl.js:122:7) at Interface.<anonymous> (repl.js:239:12) at Interface.EventEmitter.emit (events.js:95:17) at Interface._onLine (readline.js:202:10) at Interface._line (readline.js:531:8) at Interface._ttyWrite (readline.js:760:14) at ReadStream.onkeypress (readline.js:99:10) 我可以以某种方式安装它作为一个模块? 还是有其他的select? 问题是我正在下载几个RSS提要总共约900条目。 我正在下载它们不到一秒钟,但用jQuery迭代每个元素 $(xml).find('entry').each(function() { }); …需要10-15秒,这是一个Web服务是不能接受的。 有什么build议么?