Установите значение xml, используя Visual Basic - PullRequest
0 голосов
/ 27 февраля 2020

Мне нужно установить xml значения элементов динамически. Я почти закончил, но мне нужно добавить условие как указано в c часть, и это не работает. У меня есть один компонентный тег, и внутри него есть 2 раздела, первый имеет код = "62387-6", а второй имеет код = "47045-0". Мне нужно добавить специфицированный c заголовок и текст в каждом из них.

То, что я пробовал, это:

(Declared)
Private _titleReferto As String = "Title Referto"
Private _testoReferto As String = "Testo Referto"
Private _titlePrestazione As String = "Title Prestazione"
Private _testoPrestazione As String = "Testo Prestazione"


(In the function that I invoke)

            Me.setXmlValue(rootNode, Me._titleReferto, "//cr:component/cr:structuredBody/cr:component/cr:section/cr:code[@code='47045-0']/cr:title", NS)
            Me.setXmlValue(rootNode, Me._testoReferto, "//cr:component/cr:structuredBody/cr:component/cr:section[code/@code='" + "47045-0" + "']/cr:text", NS)
            Me.setXmlValue(rootNode, Me._titlePrestazione, "//cr:component/cr:structuredBody/cr:component/cr:section[code/@code='" + "62387-6" + "']/cr:title", NS)
            Me.setXmlValue(rootNode, Me._testoPrestazione, "//cr:component/cr:structuredBody/cr:component/cr:section[code/@code='" + "62387-6" + "']/cr:text", NS)

Вот как мне нужно быть xml:

 <component>
    <structuredBody>
            <component>
                <section>
                    <code code="62387-6" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" codeSystemVersion="2.64" displayName="Interventi" />    <!-- OBBL-->  
                    <title> Title Prestazione  </title>   <!-- OBBL-->  
                    <text>   <!-- OBBL-->  
                        <paragraph> 
                            <caption>Testo Prestazione</caption>   
                        </paragraph>
                    </text>
                </section>
            </component>
            <component>
                <section>
                    <code code="47045-0"  codeSystem="2.16.840.1.113883.6.1"  codeSystemName="LOINC"  codeSystemVersion="2.64" displayName="Referto" />    <!-- OBBL-->    
                    <title> Title Referto </title>   <!-- OBBL-->  
                    <text>      <!-- OBBL-->  
                        <paragraph>   
                            Testo Referto
                        </paragraph>   
                    </text> 
                </section>
            </component>
    </structuredBody>
  </component>

1 Ответ

0 голосов
/ 27 февраля 2020

XElement кажется намного проще работать с

    Dim xe As XElement
    ' xe = XElement.Load("path here") 'for production

    'for testing use a literal, before the adds
    xe = <component>
             <structuredBody>
                 <component>
                     <section>
                         <code code="62387-6" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" codeSystemVersion="2.64" displayName="Interventi"/><!-- OBBL-->
                     </section>
                 </component>
                 <component>
                     <section>
                         <code code="47045-0" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" codeSystemVersion="2.64" displayName="Referto"/><!-- OBBL-->
                     </section>
                 </component>
             </structuredBody>
         </component>

    Dim ie As IEnumerable(Of XElement)

    'select 62387-6
    ie = From el In xe...<section> Where el.<code>.@code = "62387-6" Select el Take 1

    If ie.Count = 1 Then
        Dim title As XElement = <title>Title Prestazione</title>
        ie(0).Add(title)
        Dim txt As XElement = <text><!-- OBBL-->
                                  <paragraph>
                                      <caption>Testo Prestazione</caption>
                                  </paragraph>
                              </text>

        ie(0).Add(txt)
    End If

    'then do the same for 47045-0 changing the values

    ' finally 
    '  xe.Save("path here")
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...