CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Question xmldoc SelectNodes() problems

    I've tried to use both doc.DocumentElement.SelectNodes() and doc.SelectNodes() (not sure what the difference is) to get my hand on some of the data.

    I need to get the value of:
    * m12:Singular
    * All the m12:Quantity items in the m12ose items.

    I've tried to search for "Singular", "m12:Singular", "//m12:Singular" and "Singular" but they all return an empty nodelist.

    I've added an
    Code:
                                var nsmgr = new XmlNamespaceManager(doc.NameTable);
                                nsmgr.AddNamespace("m12", "http://www.w3.org/1999/XSL/Transform");
    to my SelectNodes call (or I would get an exception).

    I hope someone has an idea. Thanks in advance.

    XML to be searched below:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <DosageProposals xsi:schemaLocation="http://xxxx.xxx/xxx/xxxx.xsd" xmlns="http://xxxx.xxx/xxx/" 
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Dosage>
        <Version>1.2.6</Version>
        <m09:DosageStructure xsi:schemaLocation="http://xxxx.xxx/xxx1/yyyy.xsd" 
                             xmlns:m08="http://xxxx.xxx/xxx1" 
                             xmlns:m09="http://xxxx.xxx/xxx1" 
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <m09:DosageTimesStructure>
            <m08:DosageTimesIterationIntervalQuantity>0</m08:DosageTimesIterationIntervalQuantity>
            <m08:DosageTimesStartDate>2010-01-01</m08:DosageTimesStartDate>
            <m08:DosageTimesEndDate>2110-01-01</m08:DosageTimesEndDate>
            <m09:DosageQuantityUnitText>zzz</m09:DosageQuantityUnitText>
            <m09:DosageSupplementaryText>zzzzz/m09:DosageSupplementaryText>
            <m09:DosageDayElementStructure>
              <m08:DosageDayIdentifier>0</m08:DosageDayIdentifier>
              <m09:AccordingToNeedDosageTimeElementStructure>
                <m08:DosageQuantityValue>1</m08:DosageQuantityValue>
              </m09:AccordingToNeedDosageTimeElementStructure>
            </m09:DosageDayElementStructure>
          </m09:DosageTimesStructure>
        </m09:DosageStructure>
      </Dosage>
      <Dosage>
        <Version>1.4.0</Version>
        <m12:Dosage xsi:schemaLocation="http://xxxx.xxx/xxx2/yyyy.xsd" 
                    xmlns:m12="http://xxxx.xxx/xxx2/yyyy.xsd" 
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <m12:Structure>
            <m12:NotIterated/>
            <m12:StartDate>2010-01-01</m12:StartDate>
            <m12:EndDate>2110-01-01</m12:EndDate>
            <m12:UnitTexts source="Doseringsforslag">
              <m12:Singular>xxxx</m12:Singular>
              <m12:Plural>xxxxx</m12:Plural>
            </m12:UnitTexts>
            <m12:SupplementaryText>xxxxxx</m12:SupplementaryText>
            <m12:AnyDay>
              <m12:Dose>
                <m12:Quantity>1</m12:Quantity>
                <m12:IsAccordingToNeed/>
              </m12:Dose>
              <m12:Dose>
                <m12:Quantity>1</m12:Quantity>
                <m12:IsAccordingToNeed/>
              </m12:Dose>
              <m12:Dose>
                <m12:Quantity>1</m12:Quantity>
                <m12:IsAccordingToNeed/>
              </m12:Dose>
            </m12:AnyDay>
          </m12:Structure>
        </m12:Dosage>
      </Dosage>
      <Dosage>
        <Version>1.4.2</Version>
    ....
      </Dosage>
    </DosageProposals>

  2. #2
    Join Date
    May 2002
    Posts
    511

    Re: xmldoc SelectNodes() problems

    Try something like:


    XmlNode xmlRoot = xmlDoc.DocumentElement;

    XmlNodeList nodes = xmlRoot.SelectNodes("/DosageProposals/Dosage/Structure/UnitTexts/Singular");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured