Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / June 2007

Tip: Looking for answers? Try searching our database.

need help with XML parser

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Nguyen - 25 Jun 2007 23:23 GMT
I can parse a simple XML file (the hard way) but do not know how to parse
the XML file (DTD and sample XML below) using System.XML.
YOur help is greatly appreciated.

Bill

<!-- DTN REFINED FUELS XML FUEL PRICE FORMAT 2-->
<!ELEMENT PRICES (TransmissionHeader, FuelPriceData+)>

<!ELEMENT AdjustedPrice (#PCDATA)>
<!ELEMENT BrandedCode (#PCDATA)>
<!ELEMENT City (#PCDATA)>
<!ELEMENT Change (#PCDATA)>
<!ELEMENT EffectiveDate (#PCDATA)>
<!ELEMENT EffectiveTime (#PCDATA)>
<!ELEMENT FuelPriceData (SupplierName, Terminal, Product)>
<!ELEMENT IsContract (#PCDATA)>
<!ELEMENT IsOutage (#PCDATA)>
<!ELEMENT Name (#PCDATA)>
<!ATTLIST Name
identType (TerminalID) #IMPLIED
ident CDATA #IMPLIED

<!ELEMENT PostedPrice (#PCDATA)>
<!ELEMENT Product (ProductName, BrandedCode, EffectiveDate, EffectiveTime,
PostedPrice, AdjustedPrice, Change, IsContract, IsOutage, TVA)>
<!ELEMENT ProductName (#PCDATA)>
<!ATTLIST ProductName
identType (ProductID) #IMPLIED
ident CDATA #IMPLIED

<!ELEMENT State (#PCDATA)>
<!ELEMENT SupplierName (#PCDATA)>
<!ATTLIST SupplierName
identType (SupplierID) #IMPLIED
ident CDATA #IMPLIED

<!ELEMENT Terminal (Name, City, State, TerminalOwner)>
<!ELEMENT TerminalOwner (#PCDATA)>
<!ATTLIST TerminalOwner
identType (TermOwnerID) #IMPLIED
ident CDATA #IMPLIED

<!ELEMENT TransmissionAgency (#PCDATA)>
<!ELEMENT TransmissionDate (#PCDATA)>
<!ELEMENT TransmissionHeader (TransmissionDate, TransmissionTime,
TransmissionAgency)>
<!ELEMENT TransmissionTime (#PCDATA)>
<!ELEMENT TVA (#PCDATA)>

<?xml version="1.0"?>

<!DOCTYPE PRICES SYSTEM "dtnxml_PriceDoc2.dtd">

<PRICES>

<TransmissionHeader>

<TransmissionDate>20070620</TransmissionDate>

<TransmissionTime>1447</TransmissionTime>

<TransmissionAgency>DTN Integrated
Services/dtnDataConnect</TransmissionAgency>

</TransmissionHeader>

<FuelPriceData>

<SupplierName identType="SupplierID" ident="0032">Hardy Oil
PB2</SupplierName>

<Terminal>

<Name identType="TerminalID" ident="1288">DMns Magellan</Name>

<City>Des Moines</City>

<State>IA</State>

<TerminalOwner identType="TermOwnerID" ident="0275">Magellan Pipeline
Company</TerminalOwner>

</Terminal>

<Product>

<ProductName identType="ProductID" ident="0024">08 Conv 87 Unleaded
Octane</ProductName>

<BrandedCode>U</BrandedCode>

<EffectiveDate>20051005</EffectiveDate>

<EffectiveTime>0001</EffectiveTime>

<PostedPrice>2.132500</PostedPrice>

<AdjustedPrice>2.132500</AdjustedPrice>

<Change>.000000</Change>

<IsContract>N</IsContract>

<IsOutage>N</IsOutage>

<TVA/>

</Product>

</FuelPriceData>

<FuelPriceData>

<SupplierName identType="SupplierID" ident="0032">Hardy Oil
PB2</SupplierName>

<Terminal>

<Name identType="TerminalID" ident="1410">Lsvl BP Oil</Name>

<City>Louisville</City>

<State>KY</State>

<TerminalOwner identType="TermOwnerID" ident="0017">BP Oil
Products</TerminalOwner>

</Terminal>

<Product>

<ProductName identType="ProductID" ident="0017">16 Low Sulfur #2 Diesel
Dyed</ProductName>

<BrandedCode>U</BrandedCode>

<EffectiveDate>20051004</EffectiveDate>

<EffectiveTime>1800</EffectiveTime>

<PostedPrice>2.584000</PostedPrice>

<AdjustedPrice>2.584000</AdjustedPrice>

<Change>.000000</Change>

<IsContract>N</IsContract>

<IsOutage>N</IsOutage>

<TVA/>

</Product>

</FuelPriceData>

</PRICES>
Martin Honnen - 26 Jun 2007 13:11 GMT
> I can parse a simple XML file (the hard way) but do not know how to parse
> the XML file (DTD and sample XML below) using System.XML.
> YOur help is greatly appreciated.

With .NET 2.0 use
  XmlReaderSettings readerSettings = new XmlReaderSettings();
  readerSettings.ProhibitDtd = false
  readerSettings.ValidationType = ValidationType.DTD;
  using (XmlReader xmlReader = XmlReader.Create(@"file.xml",
readerSettings)
  {
    while (xmlReader.Read())
    {
       // extract data here if necessary
    }
  }

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.