回答編集履歴
4
修正
test
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
次のようになります
|
2
2
|
```js
|
3
|
-
|
4
3
|
function mFunction() {
|
5
4
|
let url = 'https://elaws.e-gov.go.jp/api/1/lawdata/昭和二十五年法律第百九十七号';
|
6
5
|
let xml = UrlFetchApp.fetch(url).getContentText();
|
@@ -19,8 +18,8 @@
|
|
19
18
|
|
20
19
|
const articleCaption = article.getChild("ArticleCaption");
|
21
20
|
const articleTitle = article.getChild("ArticleTitle");
|
22
|
-
articleCaption
|
21
|
+
if (articleCaption !== null) console.log(articleCaption.getText()); // articleCaptionがnullとなる場合があるため。
|
23
|
-
articleTitle
|
22
|
+
if (articleTitle !== null) console.log(articleTitle.getText());
|
24
23
|
const paragraphs = article.getChildren("Paragraph");
|
25
24
|
if (paragraphs != null) {
|
26
25
|
paragraphs.forEach(function (paragraph) {
|
@@ -33,13 +32,14 @@
|
|
33
32
|
if (items !== null) {
|
34
33
|
items.forEach(function (item) {
|
35
34
|
const itemtitle = item.getChild("ItemTitle");
|
35
|
+
console.log("itemtitle: " + itemtitle.getText());
|
36
36
|
const itemSentence = item.getChild("ItemSentence");
|
37
|
+
console.log("itemSentence: " + itemSentence.getValue());
|
37
38
|
const columns = itemSentence.getChildren("Column");
|
38
|
-
console.log("itemtitle: " + itemtitle.getText());
|
39
39
|
if (columns !== null) {
|
40
|
-
cons
|
40
|
+
columns.forEach(function (column) { // 修正
|
41
|
-
} else {
|
42
|
-
console.log("column
|
41
|
+
console.log("column: "+column.getText());
|
42
|
+
})
|
43
43
|
}
|
44
44
|
|
45
45
|
// 以下修正
|
@@ -49,9 +49,8 @@
|
|
49
49
|
const subitem1Title = subitem1.getChild("Subitem1Title");
|
50
50
|
console.log("subitem1Title: " + subitem1Title.getText());
|
51
51
|
const subitem1Sentences = subitem1.getChildren("Subitem1Sentence");
|
52
|
-
subitem1Sentences.forEach(subitem1Sentence
|
52
|
+
subitem1Sentences.forEach(function (subitem1Sentence) {
|
53
|
-
const sentence = subitem1Sentence.getChild("Sentence");
|
54
|
-
console.log("sentence: " + sentence.get
|
53
|
+
console.log("sentence: " + subitem1Sentence.getValue());
|
55
54
|
});
|
56
55
|
});
|
57
56
|
}
|
@@ -60,4 +59,5 @@
|
|
60
59
|
});
|
61
60
|
}
|
62
61
|
});
|
62
|
+
}
|
63
63
|
```
|
3
test
CHANGED
@@ -49,8 +49,8 @@
|
|
49
49
|
const subitem1Title = subitem1.getChild("Subitem1Title");
|
50
50
|
console.log("subitem1Title: " + subitem1Title.getText());
|
51
51
|
const subitem1Sentences = subitem1.getChildren("Subitem1Sentence");
|
52
|
-
subitem1Sentences.forEach(subitem
|
52
|
+
subitem1Sentences.forEach(subitem1Sentence => {
|
53
|
-
const sentence = subitem
|
53
|
+
const sentence = subitem1Sentence.getChild("Sentence");
|
54
54
|
console.log("sentence: " + sentence.getText());
|
55
55
|
});
|
56
56
|
});
|
2
関数の記法を元質問に合わせる
test
CHANGED
@@ -45,7 +45,7 @@
|
|
45
45
|
// 以下修正
|
46
46
|
const subitem1s = item.getChildren("Subitem1");
|
47
47
|
if (subitem1s !== null) {
|
48
|
-
subitem1s.forEach(subitem1
|
48
|
+
subitem1s.forEach(function (subitem1) {
|
49
49
|
const subitem1Title = subitem1.getChild("Subitem1Title");
|
50
50
|
console.log("subitem1Title: " + subitem1Title.getText());
|
51
51
|
const subitem1Sentences = subitem1.getChildren("Subitem1Sentence");
|
1
test
CHANGED
@@ -19,10 +19,9 @@
|
|
19
19
|
|
20
20
|
const articleCaption = article.getChild("ArticleCaption");
|
21
21
|
const articleTitle = article.getChild("ArticleTitle");
|
22
|
+
articleCaption ? console.log(articleCaption.getText()) : null; // articleCaptionがnullとなる場合があるため。
|
23
|
+
articleTitle ? console.log(articleTitle.getText()) : null;
|
22
24
|
const paragraphs = article.getChildren("Paragraph");
|
23
|
-
console.log(articleCaption.getText());
|
24
|
-
console.log(articleTitle.getText());
|
25
|
-
|
26
25
|
if (paragraphs != null) {
|
27
26
|
paragraphs.forEach(function (paragraph) {
|
28
27
|
const paragraphNum = paragraph.getChild("ParagraphNum");
|