<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; WSH: Поиск и извлечение текста из XML]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=6394&amp;type=atom" />
	<updated>2011-11-03T09:37:47Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=6394</id>
		<entry>
			<title type="html"><![CDATA[Re: WSH: Поиск и извлечение текста из XML]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=53147#p53147" />
			<content type="html"><![CDATA[<p>Разобрался. Спасибо. Сделал вот так : </p><div class="codebox"><pre><code>
firm = Replace(firm,&quot;&#039;&quot;,&quot;&quot;)
firm = Replace(firm,&quot;&quot;&quot;&quot;, &quot;&quot;)
firm = Replace(firm,&quot;»&quot;, &quot;&quot;)
firm = Replace(firm,&quot;«&quot;, &quot;&quot;)</code></pre></div><p>Корректировка не нужна?</p>]]></content>
			<author>
				<name><![CDATA[KaKTuZ]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27168</uri>
			</author>
			<updated>2011-11-03T09:37:47Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=53147#p53147</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: WSH: Поиск и извлечение текста из XML]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=53146#p53146" />
			<content type="html"><![CDATA[<p>Ну если замен не очень много, то можно и обычным <strong>Replace()</strong> обойтись.</p><p>А если нужно отсеить только разрешённые символы, то наверное и так можно:<br /></p><div class="codebox"><pre><code>
Const ValidChars = &quot;0123456789abcdefghijklmnopqrstuvwxyz абвгдеёжзийклмнопрстуфхцчшщъыьэюя&quot;
&#039;Без учёта регистра
MsgBox GetOnlyValidChars(&quot;Фирма ООО ЗАО &quot;&quot;ХРЕНТУДЫСЬ&quot;&quot; ###&quot;, ValidChars, 1)
&#039;С учётом регистра
MsgBox GetOnlyValidChars(&quot;фирма ООО ЗАО &quot;&quot;ХРЕНТУДЫСЬ&quot;&quot; ###&quot;, ValidChars, 0)

Function GetOnlyValidChars(sString, ValidChars, Compare)
    Dim i, char
    For i = 1 To Len(sString)
        char = Mid(sString, i, 1)
        If InStr(1, ValidChars, char, Compare) &gt; 0 Then GetOnlyValidChars = GetOnlyValidChars &amp; char
    Next
End Function</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2011-11-03T09:25:50Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=53146#p53146</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: WSH: Поиск и извлечение текста из XML]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=53145#p53145" />
			<content type="html"><![CDATA[<p>Благодарю. Вот что получилось у меня. Но есть вопрос:</p><div class="codebox"><pre><code>Dim DOMDocument, Node, tmpStr 
Set DOMDocument = CreateObject(&quot;MSXML2.DOMDocument&quot;) 
With DOMDocument 
    .Load &quot;C:\XML\&quot; &amp; basename 
    if .parseError.reason &lt;&gt; &quot;&quot; Then 
        MsgBox .parseError.reason,vbCritical 

        WScript.Quit 

    End if 
    With .documentElement.SelectSingleNode(&quot;списокСубъектов&quot;) 
        tmpStr = &quot;&quot; 
        For Each Node in .SelectNodes(&quot;субъект&quot;) 
            sNomer = Node.GetAttribute(&quot;идентификаторСубъекта&quot;) 
             firm = Node.GetAttribute(&quot;имя&quot;)           
    MsgBox sNomer 
   MsgBox firm 
  Next 
 End With 
End With</code></pre></div><p>В поле имя иногда могут быть кавычки. А мне надо, что там были только буквы безо всяких кавычек. <br />Как мне сделать замену символов(коротко - удалить): <br />&#039; <br />&quot; <br />» <br />«</p>]]></content>
			<author>
				<name><![CDATA[KaKTuZ]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27168</uri>
			</author>
			<updated>2011-11-03T08:39:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=53145#p53145</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: WSH: Поиск и извлечение текста из XML]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=53121#p53121" />
			<content type="html"><![CDATA[<p>Любую задачу можно решить несколькими путями. Вариации на тему решения <strong>Xameleon</strong></p><p>1<br /></p><div class="codebox"><pre><code>
Option Explicit

Dim DOMDocument, Subjs, Subj, I, tmpStr
Set DOMDocument = CreateObject(&quot;MSXML2.DOMDocument&quot;)

With DOMDocument
    .Load &quot;1.xml&quot;
    if .parseError.reason &lt;&gt; &quot;&quot; Then
        MsgBox .parseError.reason,vbCritical
        WScript.Quit
    End if

    Set Subjs = .GetElementsByTagName(&quot;субъект&quot;)

    For I = 0 To Subjs.Length - 1
        tmpStr = &quot;&quot;
        tmpStr = tmpStr &amp; &quot;Идентификатор субъекта: &quot; &amp; Subjs(I).GetAttribute(&quot;идентификаторСубъекта&quot;) &amp; vbCrlf
        tmpStr = tmpStr &amp; &quot;Тип субъекта: &quot; &amp; Subjs(I).GetAttribute(&quot;типСубъекта&quot;) &amp; vbCrlf
        tmpStr = tmpStr &amp; &quot;имя: &quot; &amp; Subjs(I).GetAttribute(&quot;имя&quot;) &amp; vbCrlf
        WScript.Echo tmpStr
    Next
End With</code></pre></div><p>2<br /></p><div class="codebox"><pre><code>
Option Explicit

Dim DOMDocument, Subjs, Subj, I, tmpStr
Set DOMDocument = CreateObject(&quot;MSXML2.DOMDocument&quot;)

With DOMDocument
    .Load &quot;1.xml&quot;
    if .parseError.reason &lt;&gt; &quot;&quot; Then
        MsgBox .parseError.reason,vbCritical
        WScript.Quit
    End if

    Set Subjs = .GetElementsByTagName(&quot;субъект&quot;)

    For Each Subj In Subjs
        tmpStr = &quot;&quot;
        tmpStr = tmpStr &amp; &quot;Идентификатор субъекта: &quot; &amp; Subj.GetAttribute(&quot;идентификаторСубъекта&quot;) &amp; vbCrlf
        tmpStr = tmpStr &amp; &quot;Тип субъекта: &quot; &amp; Subj.GetAttribute(&quot;типСубъекта&quot;) &amp; vbCrlf
        tmpStr = tmpStr &amp; &quot;имя: &quot; &amp; Subj.GetAttribute(&quot;имя&quot;) &amp; vbCrlf
        WScript.Echo tmpStr
    Next</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2011-11-02T15:36:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=53121#p53121</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: WSH: Поиск и извлечение текста из XML]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=53118#p53118" />
			<content type="html"><![CDATA[<p>Хм... ну т.к Вы привели не полное содержимое XML, то мне пришлось догадываться о том где закрываются тэги.</p><p>В итоге предположил, что так<br /></p><div class="codebox"><pre><code>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;Windows-1251&quot;?&gt; 
&lt;регистрационнаяИнформация&gt; 
&lt;датаВремяФормирования&gt;2011-10-31T15:49:58&lt;/датаВремяФормирования&gt; 
&lt;списокСубъектов&gt; 
&lt;субъект идентификаторСубъекта=&quot;002-871-100318&quot; типСубъекта=&quot;АбонентСЭД&quot; имя=&quot;ООО &#039;Компенсатор&#039;&quot;&gt;
&lt;списокСертификатов типПодписанта=&quot;руководитель&quot;&gt; 
&lt;сертификат активный=&quot;true&quot;&gt;
&lt;/сертификат&gt;
&lt;/списокСертификатов&gt;
&lt;/субъект&gt;
&lt;/списокСубъектов&gt;
&lt;/регистрационнаяИнформация&gt;</code></pre></div><p>В кратце можно дёрнуть как то так наверное.<br /></p><div class="codebox"><pre><code>
Option Explicit
Dim DOMDocument, Node, tmpStr
Set DOMDocument = CreateObject(&quot;MSXML2.DOMDocument&quot;)
With DOMDocument
	.Load &quot;1.xml&quot;
	if .parseError.reason &lt;&gt; &quot;&quot; Then
	    MsgBox .parseError.reason,vbCritical
	    WScript.Quit
	End if
	With .documentElement.SelectSingleNode(&quot;списокСубъектов&quot;)
        tmpStr = &quot;&quot;
        For Each Node in .SelectNodes(&quot;субъект&quot;)
            tmpStr = tmpStr &amp; &quot;Идентификатор субъекта: &quot; &amp; Node.GetAttribute(&quot;идентификаторСубъекта&quot;) &amp; vbCrlf
            tmpStr = tmpStr &amp; &quot;Тип субъекта: &quot; &amp; Node.GetAttribute(&quot;идентификаторСубъекта&quot;) &amp; vbCrlf
            tmpStr = tmpStr &amp; &quot;имя: &quot; &amp; Node.GetAttribute(&quot;имя&quot;) &amp; vbCrlf
            MsgBox tmpStr
        Next
    End With
End With</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2011-11-02T12:52:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=53118#p53118</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[WSH: Поиск и извлечение текста из XML]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=53117#p53117" />
			<content type="html"><![CDATA[<p>Ребята. Вопрос. <br />Есть строка в XML файле : </p><div class="codebox"><pre><code>&lt;субъект идентификаторСубъекта=&quot;002-871-100318&quot; типСубъекта=&quot;АбонентСЭД&quot; имя=&quot;ООО &#039;Компенсатор&#039;&quot;&gt;</code></pre></div><p>Как вытащить идентификатор субъекта и имя компании? <br />Имеется ввиду присвоить эти данные в какие нить переменные, откуда я потом их смогу использовать. </p><p>С самого начала идентификатор субъекта вытаскивал при помощи позиции символа: <br /></p><div class="codebox"><pre><code>Set objFSO= WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;) 
  Set txtFile = objFSO.OpenTextFile(&quot;C:\XML\&quot; &amp; basename) 
  Do While Not txtFile.AtEndOfStream 
ReadLineTXT = txtFile.ReadLINE 
   If InStr(ReadLineTXT, &quot;идентификаторСубъекта=&quot;&quot;&quot;) Then 
     sNomer = mid(readlinetxt, 37, 14) 
wscript.echo sNomer 
      Exit Do 
    End If 
  Loop 
  txtFile.Close</code></pre></div><p>А вот с компании стало потруднее, поскольку каждый раз имя компании по длине менялось. </p><p>Помогите пожалуйста. </p><p>P.S. <br />Сама XML с начала выглядит так: </p><div class="codebox"><pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;Windows-1251&quot;?&gt; 
&lt;регистрационнаяИнформация&gt; 
&lt;датаВремяФормирования&gt;2011-10-31T15:49:58&lt;/датаВремяФормирования&gt; 
&lt;списокСубъектов&gt; 
&lt;субъект идентификаторСубъекта=&quot;002-871-100318&quot; типСубъекта=&quot;АбонентСЭД&quot; имя=&quot;ООО &#039;Компенсатор&#039;&quot;&gt; 
&lt;списокСертификатов типПодписанта=&quot;руководитель&quot;&gt; 
&lt;сертификат активный=&quot;true&quot;&gt;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[KaKTuZ]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27168</uri>
			</author>
			<updated>2011-11-02T11:50:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=53117#p53117</id>
		</entry>
</feed>
