小编use*_*094的帖子

计算忽略空白节点的节点

我有下面的XML.

情况1

<body>
    <nd>
        <pnn>1.1</pnn>
        <h1>PART 54</h1>
        <ti>Construction</ti>
    </nd>
    <nd>
        <h1>PART 54</h1>
        <h2>I INTRODUCT</h2>
        <ti>Time</ti>
    </nd>
    <nd>
        <h1>PART 54</h1>
        <h2>I INTRODUCT</h2>
        <ti>Power</ti>
    </nd>
    <nd>
        <h1>PART 54</h1>
        <h2>II APPLICATIONS</h2>
        <ti>Filing</ti>
    </nd>
</body>
Run Code Online (Sandbox Code Playgroud)

案例2

<body>
    <nd>
        <pnn>1.1</pnn>
        <h1>PART 54</h1>
        <h2>I INTRODUCT</h2>
        <ti>Construction</ti>
    </nd>
    <nd>
        <h1>PART 54</h1>
        <h2>I INTRODUCT</h2>
        <ti>Time</ti>
    </nd>
    <nd>
        <h1>PART 54</h1>
        <h2>II APPLICATIONS</h2>
        <ti>Filing</ti>
    </nd>
</body>
Run Code Online (Sandbox Code Playgroud)

和下面的XSLT

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

    <xsl:template match="/">
      <hmtl>
        <head>
          <title>New Version!</title>
        </head>
       <xsl:apply-templates select="body"></xsl:apply-templates> …
Run Code Online (Sandbox Code Playgroud)

xslt xslt-2.0

6
推荐指数
1
解决办法
297
查看次数

如何在 Selenium 中等待页面刷新

这是我之前的问题的扩展无法理解获取价值

这里的情况如下。

根据邮政编码,结果会有所不同。

目前我在一个文件中有以下内容。

99546
60089
Run Code Online (Sandbox Code Playgroud)

我的代码如下。

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Test1 {
    public static void main(String[] args) throws InterruptedException, FileNotFoundException {
        WebDriver driver;
        System.setProperty("webdriver.gecko.driver", "C:\\Users\\home\\Downloads\\geckodriver.exe");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        driver = new FirefoxDriver(capabilities);
        driver.get("https://www2.chubb.com/us-en/find-agent-page.aspx");

        try {
            File file = new File("zip.txt");
            FileReader fileReader = new FileReader(file);
            BufferedReader bufferedReader = new BufferedReader(fileReader); …
Run Code Online (Sandbox Code Playgroud)

java selenium automated-tests

6
推荐指数
2
解决办法
1万
查看次数

节点js中的字符串正则表达式替换

我的节点js中有以下字符串。

var textToReplace = "Your <b class =\"b_1\">1</b> payment due is $4000.Your 
<b class =\"b_1\">2</b> payment due is $3500. Your <b class =\"b_1\">3</b> 
payment due is $5000.";
Run Code Online (Sandbox Code Playgroud)

这里我想<b class =\"b_1\">*</b>''. 输出是Your 1 payment due is $4000.Your 2 payment due is $3500. Your 3 payment due is $5000.

如果这是一个正常的替换我不会有任何问题,但在这里我认为最好的替换方法是使用正则表达式。这是我感到困惑的地方。在java中我们有一个stringVariableName.replaceAll()方法。请让我知道我该怎么做。

谢谢

javascript regex string replace node.js

6
推荐指数
1
解决办法
2万
查看次数

使用POI创建XLSX文件

我有两个Java程序:一个用于创建XLSX文件并将数据写入XLSX文件,另一个用于从同一文件读取数据.

在我的第一个程序中,我使用下面的语句将数据写入XLSX文件.

FileOutputStream prelimOut = new FileOutputStream(new File("D:\\News\\Prelim.xlsx"));
XSSFWorkbook out = new XSSFWorkbook();
XSSFSheet spreadSheet = out.createSheet("ResultSheet");
Run Code Online (Sandbox Code Playgroud)

在我的驱动器上,我按预期创建了文件.

当我尝试使用此代码从不同的程序中读取相同的文件时

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class GetCellCount {
    public static void main(String[] args) throws IOException {
        FileInputStream input_document = new FileInputStream(new File("D:\\News\\Prelim.xlsx"));
        XSSFWorkbook my_xlsx_workbook = new XSSFWorkbook(input_document);
        XSSFSheet my_worksheet = my_xlsx_workbook.getSheetAt(0);
        Iterator<Row> rowIterator = my_worksheet.iterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            Iterator<Cell> cellIterator = row.cellIterator();
            while (cellIterator.hasNext()) { …
Run Code Online (Sandbox Code Playgroud)

java excel apache-poi

5
推荐指数
1
解决办法
9640
查看次数

数组索引打印错误值

我有以下Java代码.

import java.util.Arrays;

public class Cook {
    public static void main(String[] args) {
        int num[] = { 3, 1, 5, 2, 4 };
        getMaxValue(num);
    }

    public static void getMaxValue(int[] num) {
        int maxValue = num[0];
        int getMaxIndex = 0;
        for (int i = 1; i < num.length; i++) {
            if (num[i] > maxValue) {
                maxValue = num[i];
            }
        }
        getMaxIndex = Arrays.asList(num).indexOf(maxValue);
        System.out.println(getMaxIndex + " and " +maxValue);
    }   
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,我试图检索数组中的最大值以及它的索引,但这里我得到的输出是

-1 and 5
Run Code Online (Sandbox Code Playgroud)

最大值返回正常,但不确定索引有什么问题.这应该打印2,但它是打印-1,请让我知道我哪里出错了,我该如何解决这个问题.

Thankd

java

5
推荐指数
2
解决办法
1377
查看次数

如何使用 Google Places API 获取电话号码

我正在编写一段代码,以便根据用户的提示使用 Node.js 获取附近的位置,并调用 Google 的地方 API。调用如下。

https://maps.googleapis.com/maps/api/place/textsearch/json?query=garage+near+corner+of+
fifth+avenue+NY&key=myApiKey
Run Code Online (Sandbox Code Playgroud)

基本上我在这里寻找纽约第五大道附近的车库。我得到的答复如下。

{
    "html_attributions": [],
    "next_page_token": "CqQCHgEAAKUUxRRzEF_vLKTGE5CLg-kBW7K8ot040l4zcsNHEByHpvjrhZZVOWcyCiPBbtErrX9QZNQ9dZQXCaxynnaJonFjF23_PPhWAmIfIRbY40E4gFioA5o4Gm3_OjkOicROypQQlArqaf2ub6vGoMwDKU1eP8m6SFmiMwm1cS_mghR0IWJ2Q9mH5jqpPtWJd2ENX3VCrDPeoOfhaxHAg3DIG7-eh7WYMlT9r6KAERCok-fXnjI49QVrezZYK52aCY3qeLSPLeXonrE2a79jfEdV1EhpBvb4fV2SB2oysCc_xK_Kv3FW6-Ir3WK2jXslrfRvFk7sIRxtgqAlZ2xCZ43oi7DeTl5733S5j4pbFZQHgsg9grLApa_H_wTN2xN1K9UsEhIQOf7B6Gnh668FPRTZe4X78BoUOMt8UiiVZR-YDJDb5AwyME7yYuY",
    "results": [
        {
            "formatted_address": "39 W 23rd St, New York, NY 10010, United States",
            "geometry": {
                "location": {
                    "lat": 40.742537,
                    "lng": -73.99092399999999
                },
                "viewport": {
                    "northeast": {
                        "lat": 40.7437215802915,
                        "lng": -73.9896989197085
                    },
                    "southwest": {
                        "lat": 40.7410236197085,
                        "lng": -73.99239688029151
                    }
                }
            },
            "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
            "id": "b075e432a0597a31ceaf3062747999291d8d8cf7",
            "name": "Park-it 23-24 Operating Corp",
            "opening_hours": {
                "open_now": false,
                "weekday_text": []
            },
            "place_id": "ChIJJalOaKRZwokRNLnbupB5UrY",
            "reference": "CmRSAAAA-HGHWnLtBTIkRA7MlY1sjb8jDIxJQokfHSfQ_MWcLLM7lNB_MlUOwO0TcrQO8IYbUz1_l-HiehIwZ3hvg3sHEAiV-ZYpNL11gY15gz6hQsUFFKEkkfqoo_9R1PzVBd9CEhD7AxenKMzgH0LK4lNPFC8GGhSKMjd_5UnZyA3VRJrRYaw79QcxVg",
            "types": [
                "parking",
                "point_of_interest",
                "establishment" …
Run Code Online (Sandbox Code Playgroud)

google-maps google-places-api

5
推荐指数
1
解决办法
6155
查看次数

如何使用 jGit 授权用户

我正在使用 Java 并使用 jGit 创建一个应用程序。作为其中的一部分,我需要对用户进行身份验证。我想输出用户是否存在。目前我得到一个例外,如user is not authorized. 下面是我的代码。

import java.io.File;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;

public class AuthenticateanUser {

    public static void main(String[] args) throws Exception {
        final String REMOTE_URL = "https://myRepo.git";
        // prepare a new folder for the cloned repository
        File localPath = File.createTempFile("TestGitRepository", "");
        localPath.delete();
        // then clone
        try (Git result = Git.cloneRepository().setURI(REMOTE_URL)
                .setCredentialsProvider(new UsernamePasswordCredentialsProvider("myId", "myPwd"))
                .setDirectory(localPath).call()) {

            System.out.println("Having repository: " + result.status());
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

当我运行上面的代码时,如果我提供正确的凭据,我得到的输出为

Having repository:XXXXX
Run Code Online (Sandbox Code Playgroud)

如果我提供错误的凭据,我会收到错误消息

Exception in thread "main" org.eclipse.jgit.api.errors.TransportException: https://myRepo.git: …
Run Code Online (Sandbox Code Playgroud)

java jgit

5
推荐指数
1
解决办法
2931
查看次数

使用 aws 发送短信时感到困惑 [更新:短信发送太晚了]

我正在编写一个使用 AWS SNS 服务发送 SMS 的程序。我是这个话题的新手。所以我尝试了在线提供的代码之一。

代码如下。

var AWS = require('aws-sdk');

AWS.config.region = 'your aws region';
AWS.config.update({
    accessKeyId: "your access id",
    secretAccessKey: "your secret access key",
});

var sns = new AWS.SNS();
var params = {
    Message: "your message",
    MessageStructure: 'string',
    PhoneNumber: 'phone_number_without_+',
    Subject: 'your subject'
};

sns.publish(params, function (err, data) {
    if (err) console.log(err, err.stack); // an error occurred
    else console.log(data);           // successful response
});
Run Code Online (Sandbox Code Playgroud)

在这里,我填充了来自 AWS 控制台的全部数据,例如Region, accessKeyand secretAccessKey, my mobile number, Subject …

amazon-web-services node.js amazon-sns

4
推荐指数
1
解决办法
2216
查看次数

无法动态创建和附加div和span

我正在写一个有代码的HTML代码,y这是在我的HTML正文中,并且有一个按钮.当用户点击此按钮时,我想执行以下操作.

  1. 创建另一个div(类为smallBar)
  2. 在这里div,我想创建3个跨度.
  3. 将此(总smallBar)内容添加到div y.

这是我目前的代码.

HTML

<div class="y" id="y">

</div>
<input type="button" onclick="createDiv()" value="click me" />
Run Code Online (Sandbox Code Playgroud)

JS

function createDiv() {
  var div = document.createElement("div");
  div.className = "smallBar";
  var span1 = document.createElement("span");
  span1.className = "span1";
  var span2 = document.createElement("span");
  span2.setAttribute("class", "span1");
  var span3 = document.createElement("span");
  span3.setAttribute("class", "span1");

  div.appendChild(span1);
  div.appendChild(span2);
  div.appendChild(span3);

  document.getElementById("y").innerHTML = div;
}
Run Code Online (Sandbox Code Playgroud)

在这里,当我点击按钮,而不是创建div它是给我消息[object HTMLDivElement].请让我知道我哪里出错了,我该如何解决这个问题.

这是我的小提琴https://jsfiddle.net/d9hg0vkk/

谢谢

html javascript

4
推荐指数
1
解决办法
44
查看次数

在 JavaScript 中动态创建 JSON 数组键

我有一个正在创建的 JSON for-loop

这里我的主要要求是Key从预定义的变量创建。

这是我正在使用的代码。

var rows =["Hello Trt", "Ho there", "I'm up"];
var name="Hello";
var jsonData = {};
var intentName=[];
var mainPersonel = {};
var intents = {};
intents.intentName = rows;
mainPersonel.intents=intents;
console.log(JSON.stringify(mainPersonel));
Run Code Online (Sandbox Code Playgroud)

查看其他 SO 帖子,我可以找到有关如何替换intents变量的信息,但在我的情况下,我想在输出中替换intentNamename

预期输出是

{"intents":{"Hello":["Hello Trt","Ho there","I'm up"]}}
Run Code Online (Sandbox Code Playgroud)

请让我知道如何实现这一目标。

谢谢

javascript json

4
推荐指数
1
解决办法
74
查看次数